Support » Requests and Feedback » WP_Query->query returns wrong number of posts if select after meta_key/meta_valu

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

    $recentPosts->query('meta_key=wp_release_id&meta_value=may&category_name=startseite&posts_per_page=2');

    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 -.-

Viewing 2 replies - 1 through 2 (of 2 total)
  • See if this works:

    <?php
    $cat_id = get_cat_ID('startseite');
    $args=array(
      'cat' => $cat_id,
      'meta_value'=> 'may',
      'meta_key'=>'wp_release_id',
      '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>
        <?php
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

    Thread Starter lautr

    (@lautr)

    looks pretty good, THX!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘WP_Query->query returns wrong number of posts if select after meta_key/meta_valu’ is closed to new replies.