0

i want show last 3 days posts Randomly. how can i edit this code?

<?php
$randompost = array(
'numberposts' => 2,
'type' => 'news',
'orderby' => 'rand',
'year' => date( 'Y' ),
'week' => date( 'W' ),
);
$rand_posts = get_posts( $randompost );
foreach( $rand_posts as $post ) : ?>
<?php endforeach; ?>
0

You can use this code for show last 3 days post. Best of luck...

$args = array(
    'post_status' => 'publish',
    'type' => 'news',
    'posts_per_page' => 2,
    'order' => 'rand',
    'date_query' => array(
        array(
            'after' => '3 days ago'
        )
    )
);
1

You can use the code below:

$today = getdate();
$randompost = array(
    'date_query' => array(
        array(
            'before'     => '3 days ago',
            'after'    => array(
                'year'  => $today['year'],
                'month' => $today['mon'],
                'day'   => $today['mday'],
            ),
        ),
    ),
    'numberposts' => 2,
    'type' => 'news',
    'orderby' => 'rand',
  );

$rand_posts = get_posts( $randompost );
if ( $rand_posts ) {
foreach ( $rand_posts as $post ) : 
    setup_postdata( $post );
    ?>
    <!-- Your Markup Here -->
    <?php
endforeach; 
wp_reset_postdata();
}
?>

See more details here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.