WordPress.org

Ready to get started?Download WordPress

Forums

Sort Query Posts
How to randomize ALL posts within a category (3 posts)

  1. DonnaMiller
    Member
    Posted 2 years ago #

    I'm using the plugin to randomize posts within each category. What I've noticed is that it actually doesn't randomize all posts in a category, but rather shuffles the order of the posts that appear on each archive page. Is there a way to get it to randomize ALL posts within a category so that different posts can appear on the first archive page?

    http://wordpress.org/extend/plugins/sort-query-posts/

  2. Tubal
    Member
    Plugin Author

    Posted 2 years ago #

    but rather shuffles the order of the posts that appear on each archive page.

    Yes, that's the intended behavior.

    Is there a way to get it to randomize ALL posts within a category so that different posts can appear on the first archive page?

    Not with this plugin.

    Regards,

    Túbal

  3. Sandip Patil
    Member
    Posted 2 years ago #

    Try Below code..

    1. Select the post from category:
    $args = array('cat' => $category_id,'post_status' =>'publish','posts_per_page'=>-1,'orderby' => 'post_date','order'=>'DESC');
    $random_posts_arr = query_posts($args);

    2. shuffle or randomize the post array...
    $post_arr = shuffle($random_posts_arr);

    3. Then traverse the post array ($post_arr) to show the post data (title, link, image, date)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic