Support » Fixing WordPress » Random Daily Post?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter falarious

    (@falarious)

    <?php
    
        $args=array(
          'id'=>'1',
          'post_type' => 'post',
          'post_status' => 'publish',
          'posts_per_page' => 1,
          'caller_get_posts'=> 1
          );
        $my_query = null;
        $my_query = new WP_Query($args);
        if( $my_query->have_posts() ) {
          echo 'List of Posts';
          while ($my_query->have_posts()) : $my_query->the_post(); ?>
          <br /><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a><br /><?php the_content(); ?>
           <?php
          endwhile;
        }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

    I have that code and it pulls the post with ID=1. How can I make it so that it will pull a random post, every day.

    Thread Starter falarious

    (@falarious)

    I don’t want a random post each time I refresh the page.

    I want only 1 random post to be chosen for the day, and kept there for the rest of the day.

    Come tomorrow, it will pick another random post.

    Thread Starter falarious

    (@falarious)

    Finally got something to work.
    $d will get the day of the year.

    WP_Query(‘p=’.$d.”)
    Gets the post ID according to the day of the year.

    Its not really random, but it will do for now.

    <h2 class="widgettitle">Daily Post</h2>
    <?php $d = date('z'); ?>
       <?php $my_query = new WP_Query('p='.$d.''); ?>
          <?php while ($my_query->have_posts()) : $my_query->the_post(); ?>
              <div class="post" id="post-<?php the_ID(); ?>">
    	   <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a> <br /> <?php the_content(); ?>
    			</div>
    <?php endwhile; ?>

    Did you ever figure out how to do it this way:

    I don’t want a random post each time I refresh the page.

    I want only 1 random post to be chosen for the day, and kept there for the rest of the day.

    Come tomorrow, it will pick another random post.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Random Daily Post?’ is closed to new replies.