Slow SQL query
-
Hi,
New here at the forum (except for reading sometimes without being logged in) and need some help π
I need to get a custom menu from another site (sharing the same MySql but different databases).
I’m doing it this way:
function get_main_site_menus($custom_menu) { global $wpdb; $mydb = new wpdb('root','xxx','xxx','localhost'); $menu_items = ''; $custom_menu_items = $mydb->get_results(" SELECT p2.post_title, p2.guid FROM wp_posts p1 LEFT JOIN wp_term_relationships AS TR ON TR.object_id = p1.ID LEFT JOIN wp_postmeta AS PM ON pm.post_id = p1.ID LEFT JOIN wp_posts AS p2 ON p2.ID = PM.meta_value WHERE p1.post_type = 'nav_menu_item' AND TR.term_taxonomy_id = ( SELECT wp_terms.term_id FROM wp_terms WHERE wp_terms.slug = '$custom_menu') AND pm.meta_key = '_menu_item_object_id' ORDER BY p1.menu_order ASC "); if ($custom_menu_items) { foreach($custom_menu_items as $custom_menu_item) { $menu_items .= ' <li><a>guid . '">' . $custom_menu_item->post_title . '</a></li> '; } } return $menu_items; }The problem is that this slows down the page with about two seconds of loadtime. Why is this function or SQL query that slow? What can I do to improve it?
Thanks in advance for any help!
The topic ‘Slow SQL query’ is closed to new replies.