Site icon Hip-Hop Website Design and Development

Choose a random publish from a selected class?

I am very new to phrase press having solely put in it on the weekend, I am superb with HTML & CSS however PHP & WordPress is alien to me.

I am attempting to show a publish from a selected class that adjustments day-after-day, i’ve searched all over the place and located the under code whihc works to some extent.

I simply cant appear to get it to select from a class quantity?

Any assist or rationalization can be a lot appreciated.

    <?php
if ( false === ( $totd_trans_post_id = get_transient( 'totd_trans_post_id' ) ) ) {
     $args = array('numberposts' => 1, 'orderby' => 'rand');
     $totd = get_posts($args);
     $midnight = strtotime('midnight +1 day');
     $timenow = time();
     $timetillmidnight = $midnight - $timenow;
     echo $midnight;
     echo ",".$timenow;
     set_transient('totd_trans_post_id', $totd[0]->ID, $timetillmidnight);
} else {
    $args = array('post__in' => array($totd_trans_post_id));
    $totd = get_posts($args);
}

foreach( $totd as $publish ) : setup_postdata($publish); ?>
    <div>
        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
        <?php the_content(); ?>
    </div>
<?php endforeach; ?>

EDIT Thanks for the strategies however nothing appears to be working with my present code, it nonetheless continues to choose a completey random publish from all classes.