WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. lautr
    Member
    Posted 4 years ago #

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

  2. MichaelH
    Member
    Posted 4 years ago #

    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().
    ?>
  3. lautr
    Member
    Posted 4 years ago #

    looks pretty good, THX!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.