Forums

[resolved] Random posts from one category? (3 posts)

  1. dlogan
    Member
    Posted 2 years ago #

    Hello,

    I have some code on a WordPress site and here it is currently:

    <?$my = new WP_Query('category_name=header&showposts=1&orderby=date&order=DESC')?>
    				<?php if ($my->have_posts()) : ?>
    					<?php while ($my->have_posts()) : $my->the_post(); ?>
    					<img src="<?php echo get_meta_image_url(get_post_meta(get_the_ID(), "Header Image", true))?>" alt="#" />
    					<?endwhile;?>
    				<?endif;?>

    How would I make it pick 1 random post from that category in the above code?

    Thanks.

  2. esmi
    Theme Diva & Forum Moderator
    Posted 2 years ago #

    You could just try changing orderby=date to orderby=rand in the first line.

  3. dlogan
    Member
    Posted 2 years ago #

    Awesome. So simple, yet so awesome :) Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic