I need to have 5 random posts on post page (http://7cuteoutfits.com/2015/07/08/suits-rachel-z-office-fashion/) excluding current post. Random posts should be on chosen dates (for example posts from last 2 months until yesterday )
I added a few lines of code to single.php of my wordpress and now have 5 random posts. So I need to modify the code so that it will meet my requirements (above). I think it’s 2 more lines, I’ll be very thankful if you help.
<ul>
<?php
$currentID = get_the_ID();
$args = array( 'posts_per_page' => 5, '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(); ?>
</ul>
You can use WP_Query for that.
This query orders randomly posts between today (inclusive) and Jan. 1st 2015
I haven’t tested the snippet here, so please let me know if it does not work for you.
More info on WP_query and its usage (also for date parameters) here
Once you query with WP_Query, you have to
just as you are already doing.
EDIT:
To show the post content, you can call
to print it directly, or
to get it as a return value. Then you can handle the printing later with the HTML markup you desire.