I have a project that contains a button supposed to generate get a link to a random Custom Post item.
I made my Custom Query as follow:
<div class="content"> <?php $argsRandItem = array( 'post_type' => 'participant', 'posts_per_page' => 1, 'orderby' => 'rand' ); $queryRandItem = new WP_Query($argsRandItem); if ($queryRandItem->have_posts() ) : while ( $queryRandItem->have_posts() ) : $queryRandItem->the_post(); ?> <a class="btn_blue" href="<?php the_permalink(); ?>">Discover a Project</a> <p><?php the_title(); ?></p> <hr> <?php endwhile; wp_reset_postdata(); endif; ?> </div>
The most strange thing is that the solution is working well on my local environment, and even on a pre-prod server as well. However, when the website is put online Live the button is always returning as a result a link to 1 specific post (Coincidentally - or not - the first one showing on the list of this Custom Post type).
I cannot imagine what could be a reason for this to be happening. The live version has enough items posted. Is it a normal bug on random Custom Post Type elements?