posts_per_page not working with custom post type
-
I have a custom post type (deal) set up, with custom taxonomy (deals), and a loop in a template file to display 5 links to posts of that custom post type, but it will only show 2 no matter what I do….here’s my loop:
<?php global $post; $today = time('now'); $args = array( 'post_type' => 'deal', 'deal_category' => 'deals', 'posts_per_page' => 5, 'meta_key' => 'date_end', 'orderby' => 'meta_value_num', 'order' => 'ASC'); $myposts = get_posts( $args ); foreach ( $myposts as $post ) : setup_postdata( $post ); $exp_date = get_post_meta($post->ID,'date_end',true); $expiration_date = strtotime($exp_date); if ($expiration_date > $today) { ?> <li> <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> </li> <?php } endforeach; wp_reset_postdata(); ?>
I know I have more than two posts in this custom post type with the ‘deals’ category assigned to them, and they are not expired (not past the date_end)…..but I cannot figure out how to make it show more than 2 posts. I even tried “numberposts” instead of “posts_per_page” but that didn’t work.
This loop is NOT going on a taxonomy page so I don’t think using solutions I’ve found here that others have posted will work as those involved setting a specific number of posts in the functions.php using if_tax()….it’s being used on a page where there are multiple loops already working correctly for other post types.
Any suggestions?
- The topic ‘posts_per_page not working with custom post type’ is closed to new replies.