• Resolved neoarmenia

    (@neoarmenia)


    While using query with the argument orberby=rand, it shows random posts, but the same post repeats again and again for several times, how can I make the random post list uniquely random, so that a post would show only once?

    query_posts('orderby=rand&order=ASC&limit=1');
    if (have_posts()) {
    	while (have_posts()) {
    		the_post();
    /*SOME CODE HERE USING RANDOM POSTS*/
    } else {
    /*NO RESULTS*/
    }
Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator t-p

    (@t-p)

    Try this:

    <?php
                   $args = array( 'posts_per_page' => 1, 'orderby' => 'rand' );
    
    $rand_posts = get_posts( $args );
    foreach ( $rand_posts as $post ) :
    setup_postdata( $post ); ?>
    <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
    <?php endforeach;
    wp_reset_postdata(); ?>
    Thread Starter neoarmenia

    (@neoarmenia)

    It showed one post only, and when I changed posts per page to 8, it showed the same post for 8 times. No randomness, no uniqueness.

    Moderator t-p

    (@t-p)

    when I changed posts per page to 8, it showed the same post for 8 times.

    When I change that to 8 in my testing, I see eight random posts.

    What theme are you using? where did you download it from?

    Have you tried:
    -deactivating ALL plugins temporarily to see if this resolves the problem. If this works, re-activate them individually (one-by-one) to find the problematic plugin(s). If you can’t get into your admin dashboard, try deactivating via FTP or SFTP or whatever file management application your host provides. If applicible, also remember to deactivate any plugins in the mu-plugins folder. The easiest way is to rename that folder to mu-plugins-old.
    – To rule out any theme-specific issue, try switching to the unedited default theme for a moment using the WP dashboard. If you don’t have access to your admin area, you can switch to the default theme by renaming your current theme’s folder in wp-content/themes and adding “-old” to the end of the folder name using via FTP or SFTP or whatever file management application your host provides. Alternately, you can remove other themes except the default theme. That will force your site to use it.
    resetting the plugins folder by FTP or PhpMyAdmin. Sometimes, an apparently inactive plugin can still cause problems (because the hooks remain unless plugins completely removed or some plugins stick around in cached files. So by renaming the folder, you break them and force them inactive).

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Showing unique random only’ is closed to new replies.