• hello this is my code to randomize posts
    i have posted this on archives.php on line 16

    <?php query_posts(“orderby=rand”); ?>

    , but this code mixes all the categories on page , i want to not mix the categories but to work only for that specific category ..

    Does anyone know how to complete that code to work only for specific category, to randomize only posts on that category,

    thank you

    https://www.ads-software.com/plugins/random/

Viewing 2 replies - 1 through 2 (of 2 total)
  • did you mean you edited archive.php (no s at the end)?

    archives.php would likely be a custom page template, which is theme specific.

    generally, don’t use ‘query_posts()‘,

    try to work with 'pre_get_posts' https://codex.www.ads-software.com/Plugin_API/Action_Reference/pre_get_posts

    example code to be added into functions.php of your (child) theme:

    function randomize_archive_posts( $query ) {
        if ( $query->is_archive() && $query->is_main_query() ) {
            $query->set( 'orderby', 'rand' );
        }
    }
    add_action( 'pre_get_posts', 'randomize_archive_posts' );
    Thread Starter artmusliu

    (@artmusliu)

    okay i will try to use pre_get_posts,

    thank you for your time…

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘i need help for completing some little code, orderby=rand’ is closed to new replies.