WP_Query->query returns wrong number of posts if select after meta_key/meta_valu (3 posts)

  1. lautr
    Posted 6 years ago #

    Okay, i have a rather tricky Problem with the wp_query->query method, mine looks like:


    but he does not return 2 Posts in all cases, for example if there are 4 Posts for the Category 'startseite' of wich the 2 newest ones dont have the meta_key and meta_value i look for he returns zero posts.

    Its like he makes an Select with everything besides the meta stuff, and then makes a 'Sub'Select for the meta stuff on the given result.

    Is this a known or a new WP Bug? (or hoooooopefully i made a mistake, if so PLEEEASE tell me) ... that thing is killing me -.-

  2. MichaelH
    Posted 6 years ago #

    See if this works:

    $cat_id = get_cat_ID('startseite');
      'cat' => $cat_id,
      'meta_value'=> 'may',
      'post_type' => 'post',
      'post_status' => 'publish',
      'posts_per_page' => -1,
      'caller_get_posts'=> 1
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      echo 'List of Posts';
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
    wp_reset_query();  // Restore global post data stomped by the_post().
  3. lautr
    Posted 6 years ago #

    looks pretty good, THX!

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.