if I use a query with a random order (orderby=rand), I see the same posts in more than one page. For exemple, i see a post in the first page, and then the same post is in the second page, too.
Can someone help me?
Thank you.
Here my code:
<?php query_posts($query_string . ‘&orderby=rand’); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
…
<?php endwhile; ?>
]]><?php $my_query = new WP_Query('category_name=products&orderby=rand&showposts=5'); ?>
<?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
<li>
<a href="<?php
$url = get_post_meta($post->ID, 'productURL', true);
if ($url) {
echo "$url";
}
?>" target="_blank"><?php the_post_thumbnail() ?>
<h2>
<?php the_title(); ?>
</h2>
</a></li>
<?php endwhile; ?>
above simple random post it was work before fine now don’t
<?php $testo_query = new WP_Query('category_name=testimonials&orderby=rand&showposts=1'); ?>
<?php while ($testo_query->have_posts()) : $testo_query->the_post(); ?>
<?php the_content(); ?>
<div class="author">
<?php the_title(); ?>
<br>
<?php the_field('position'); ?>
</div>
<?php endwhile; ?>
none is work.
guys any idea why not work.. how to make it work .
]]>My post loop code:
<?php
global $post;
$cat = get_search_query();
$randomoyun = get_posts('numberposts=4&offset=0&orderby=rand&s='.$cat);
foreach($randomoyun as $post) :
setup_postdata($post);;
?>
https://www.ads-software.com/extend/plugins/search-everything/
]]>query_posts($query_string . '&orderby=rand');
to randomize the order of the posts within my categories.If I then click on the “newer” nav link, the original randomization is gone.
Is there a way to randomize once, then have that order remain in tact while navigating through a category using the navigation links?
Here is a link to my site where you can see what I am talking about when you click any of the menu items.
https://theviolent.net
Thanks!!
–christopher
Currently if I have 100 posts, split them over 10 pages and order them randomly, the same post can appear several times through the pages. Now this might not seem like a huge issue but the big part of this problem is that not all posts are displayed. This is because of the repeated posts.
]]>I’ve successfully used the “orderby=rand” argument to create a random listing of a single category on a page. To be more specific, the category is “Member” and the page is a list of the title and a custom field for member profiles. My problem is, there are currently 58 members, and more are expected to join (probably no more than 150 or so), and I would like to split these member excerpts across multiple pages.
Unfortunately, as you know, with the “orderby=rand” argument alone, there is no guarantee that subsequent pages won’t repeat posts, as it re-randomizes each page without taking into account what’s already been displayed. So my question is, how do I randomize my posts across multiple pages? If I’m not making sense, this person described the exact same problem.
I’ve searched the forums and found the suggestion that I replace <?php query_posts('orderby=rand'); ?>'
with `<?php $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1;
query_posts($query_string.’&orderby=rand&paged=’,$paged); ?>`, but it didn’t work for me.
I also Googled the problem and found a general PHP solution: $offset_result = mysql_query( " SELECT FLOOR(RAND() * COUNT(*)) AS
offsetFROM
table` “);
$offset_row = mysql_fetch_object( $offset_result );
$offset = $offset_row->offset;
$result = mysql_query( ” SELECT * FROM table
LIMIT $offset, 1 ” );`
But I don’t really understand WordPress, PHP, or MySQL well enough to know if I can utilize that, and if I can, how to utilize it.
Thanks for taking the time to consider my query.
Scott
]]><div id="loop1">
<?php query_posts('cat=6&showposts=1&orderby=rand'); ?>
<?php $posts = get_posts('category=6&numberposts=1&offset=0'); foreach ($posts as $post) : start_wp(); ?>
<?php the_content(); ?>
<?php endforeach; ?>
</div>
Both loops are exactly the same but use a different category. I know the loops work because the last post of each is displayed, the only problem is orderby=rand is not loading anything different on a reload.
Any help with the issue would be appreciated. If you have questions please ask.
]]>