SQL-Abfrage mit wpdb in WordPress

Benötigen Sie Hilfe bei meiner Suchanfrage, um die Ladezeit zu verbessern (derzeit 4 Sekunden). Das ist meine wp Frage:

function show_search_query($query) { global $my_category_id; if (!is_admin() && $query->is_main_query() && is_search() ) { $exclude_ids = array( 1905, 6913, 6935, 6997, 7000, 7001, 7122, 7839, 7840, 7843, 7844, 64358, 68491, 68495, 68529, 70408, 71076, 71078, 71081, 71462, 71722, 72191, 74944, 80011, 80462, 88221, 88395, 88695, 81204, 89801, 96233, 155950, 183042, 184246, 188149, 195937, 196686, 197755, 199995, 202190, 232857 ); $query->set( 'post__not_in', $exclude_ids); $query->set( 'posts_per_page', 10 ); $query->set( 'cat', $my_category_id ); $query->set( 'post_type', array('post','guides','community','local-news','page','print','local','corporate','ajde_events') ); $query->set( 'orderby', 'date' ); $query->set( 'order', 'DESC' ); $query->set( 'date_query', array('column'=>'post_date','after'=> '- 365 days')); } } add_action( 'pre_get_posts', 'show_search_query'); 

Generiertes SQL (search = san marcos):

 SELECT SQL_CALC_FOUND_ROWS DISTINCT wp_posts.ID FROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) LEFT JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id WHERE 1=1 AND ( wp_posts.post_date > '2016-08-15 10:05:45') AND wp_posts.ID NOT IN (1905,6913,6935,6997,7000,7001,7122,7839,7840,7843,7844,64358,68491,68495,68529,70408,71076,71078,71081,71462,71722,72191,74944,80011,80462,88221,88395,88695,81204,89801,96233,155950,183042,184246,188149,195937,196686,197755,199995,202190,232857) AND ( wp_term_relationships.term_taxonomy_id IN (14)) AND (((wp_posts.post_title LIKE '%san%') OR (wp_postmeta.meta_value LIKE '%san%') OR (wp_posts.post_excerpt LIKE '%san%') OR (wp_posts.post_content LIKE '%san%')) AND ((wp_posts.post_title LIKE '%marcos%') OR (wp_postmeta.meta_value LIKE '%marcos%') OR (wp_posts.post_excerpt LIKE '%marcos%') OR (wp_posts.post_content LIKE '%marcos%'))) AND wp_posts.post_type IN ('post', 'guides', 'community', 'local-news', 'page', 'print', 'local', 'corporate', 'ajde_events') AND (wp_posts.post_status = 'publish' OR wp_posts.post_author = 7 AND wp_posts.post_status = 'private') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 10 

Nach der Überprüfung der generierten SQL, bemerkte, dass die LIKE-Teile die performance beeinträchtigen, also änderte ich die Abfrage mit MATCH und die Ladezeit verbesserte sich auf 0,270 Sekunden:

 SELECT SQL_NO_CACHE SQL_CALC_FOUND_ROWS DISTINCT wp_posts.ID FROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) LEFT JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id WHERE 1=1 AND ( wp_posts.post_date > '2016-08-04 10:45:30') AND wp_posts.ID NOT IN (1905,6913,6935,6997,7000,7001,7122,7839,7840,7843,7844,64358,68491,68495,68529,70408,71076,71078,71081,71462,71722,72191,74944,80011,80462,88221,88395,88695,81204,89801,96233,155950,183042,184246,188149,195937,196686,197755,199995,202190,232857) AND ( wp_term_relationships.term_taxonomy_id IN (14)) AND (( MATCH (wp_posts.post_title, wp_posts.post_excerpt, wp_posts.post_content) against ('%san%') OR (wp_postmeta.meta_value LIKE '%san%') ) AND (MATCH (wp_posts.post_title, wp_posts.post_excerpt, wp_posts.post_content) against ('%marcos%') OR (wp_postmeta.meta_value LIKE '%marcos%') ) ) AND (wp_posts.post_password = '') AND wp_posts.post_type IN ('post', 'guides', 'community', 'local-news', 'page', 'print', 'local', 'corporate', 'ajde_events') AND (wp_posts.post_status = 'publish') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 10 

Meine Frage ist, wie die vorherige SQL-Abfrage mit WP_query oder $ wpdb zu erreichen? Irgendwelche Vorschläge? Danke im Voraus!

Solutions Collecting From Web of "SQL-Abfrage mit wpdb in WordPress"