Forums

random posts in one category + 15 posts back (1 post)

  1. cellobrutos
    Member
    Posted 1 year ago #

    Hi,

    I'm looking for a way in a custom query to fetch 5 random posts among the last 15 posts in one given category. Is there a way to do this?

    Right now this is what I've got:

    <?php global $post;
    	$args = array(
            'orderby' => 'rand',
    	'numberposts' => 5,
    	'category' => 5
    	);
    	$myposts = get_posts( $args );
    	foreach( $myposts as $post ) : setup_postdata($post); ?>

    Which gives me 5 random posts that are in category 5, but with no limit back in time/posts numbers.

    Thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic