0

I have a custom post type named 'album' and I added two custom fields 'release_date' and 'release_date_us' with the ACF plugin.

I'm trying to display the latest albums based in a widget area. The number of albums to show is set with my widget.

Here is the query I use in my widget :

<?php
    // WP_Query argument
    $arg = array(
      'post_type' => 'album',
      'meta_query' => array(
        array(
          'key' => 'release_date', // albums with release_date value less or equal than today
          'value' => date(Ymd),
          'compare' => '<=',
        ),
        array(
          'key' => 'release_date_us', // albums with release_date_us value less or equal than today
          'value' => date(Ymd),
          'compare' => '<=',
        ),
      ),
      'post_per_page' => $instance['number'] // number of albums to show. This is set to 1 in my widget
      'order' => 'DESC',
    );
    // The Query
    $query = new WP_Query( $args );
    // The Loop
    if ( $query->have_posts() ) {
      while ( $query->have_posts() ) {
        $query->the_post();
?>
        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
<?php
      }
    }
    // Restore original Post Data
    wp_reset_postdata();
?>

My problem is that post_per_page parameter seems to be ignored.

The widget returns the three albums I created, not the last one as I expected.

What am I doing wrong?

EDIT : I figured it out. I was using 'post_per_page' instead of 'posts_per_page'...

1 Answer 1

2

The parameter is called:

posts_per_page

so you are missing the plural »s« - more information about WP_Query - Pagination Parameters at the codex.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.