0
 wp_reset_query();
 wp_reset_postdata();
 $post = null;
 $course_args = array(
     'post_status' => 'publish',
     'post_type' => 'course',
     'posts_per_page' => 5,
     'order' => 'DESC',
     'orderby' => 'date',
     'tax_query' => array(
         array(
             'taxonomy' => 'course_cats',
             'terms' => array($category_id),
         ),
     ),
 );
 $course_args['meta_query'] = array(
     'relation' => 'AND',
     array(
         'key' => 'type',
         'value' => array('type1'),
         'compare' => '=',
     ),
 );
 $query_courses = new WP_Query($course_args);

Request "SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN (1835) ) AND ( ( wp_postmeta.meta_key = 'tip_kursa' AND wp_postmeta.meta_value = 'paid' ) ) AND wp_posts.post_type = 'course' AND ((wp_posts.post_status = 'publish')) GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC LIMIT 0, 1"

I have disabled all plugins except ACF, it is filtered by its field. Disabled function.php and all the extra code.

11
  • there is no get_posts call in that code, can you provide more context? What's the purpose of wp_reset_query and where is the pagination code? Do you have pre_get_posts filters? The query in the question does not specify a page, and it looks like you have a type meta field that would be better as a custom taxonomy
    – Tom J Nowell
    Commented May 23 at 14:08
  • corrected the title. pre_get_posts no, I disabled everything and deleted it. The taxonomy is already in use, of course i can create another one, but a field is more convenient. There is no pagination, just 5 posts. Commented May 23 at 17:33
  • @Tom J Nowell and this only happens on the post page; on the other taxonomy page everything is displayed consistently. Commented May 23 at 17:36
  • querying for posts via the values of meta fields doesn't scale that's what the taxonomy system was added for. Meta is fast when you already know which post ID you want, making get_post_meta etc super fast, but searching for posts gets slower as the size of the meta table increases. Can you answer my other questions? It's unclear where this code runs, the URL and template this code is in, as well as what the code for the loop that displays the courses looks like. Also you said there is no pagination in your comment, but your question mentions different pages in its title can you explain?
    – Tom J Nowell
    Commented May 24 at 12:49
  • And where does $category_id come from?
    – Tom J Nowell
    Commented May 24 at 12:51

0

Browse other questions tagged or ask your own question.