• I am currently using the Get-a-post plugin which allows me to put a single post in the header based on the post number I choose. This is what I have:

    <?php get_a_post(234); ?> which pulls the post with the_id() of 234. I then added the following code:

    <?php srand(time());
    $random = (rand()%319); ?>

    and replaced <?php get_a_post(234); ?> with <?php get_a_post($random); ?>

    This is all fine and dandy, but when the random number generator picks a number from a post that is not published and may or may not exist, the results are blank.

    Is there a way to define the array from which the random numbers can be chosen that is drawn directly from the database such that if a post is added or removed the script will adjust?

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘How do I fetch a post ID randomly from published posts?’ is closed to new replies.