Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

How would I make a widget to display a random post's image and permalink? I would like it to pull from a specific custom content type and only posts have set the custom field of "featured" to "yes".

share|improve this question

1 Answer 1

<?php query_posts( 'cat=36&post_type=athletes&showposts=1&orderby=rand'); ?>

changed to :

      <?php
$args = array( 'numberposts' => 36,'category'  => '1','post_type'  => 'athletes', 'orderby' => 'rand');


$lastposts = get_posts( $args );
foreach($lastposts as $post) : setup_postdata($post); ?>
    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
<?php endforeach; ?>
share|improve this answer
    
Don’t use query_posts() if you don’t want to overwrite the main query. –  toscho Jun 24 '12 at 18:22
    
@toscho I changed my code (see edit) but now nothing is displaying. Title of unrelated post. –  Sam Jun 24 '12 at 18:34

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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