Skip to content

Instantly share code, notes, and snippets.

@karlazz
Last active December 20, 2015 05:49
Show Gist options
  • Save karlazz/6081388 to your computer and use it in GitHub Desktop.
Save karlazz/6081388 to your computer and use it in GitHub Desktop.
Simple wp_query example
$random_post = new WP_query();
$random_post->query('cat=3&showposts=1&orderby=rand');
while ($random_post->have_posts()) : $random_post->the_post();
<a href="<?php the_permalink() ?>" title="<?php the_title(); ?>">
<img src="<?php echo get_post_meta($random_post->ID, 'featured', true); ?>">
</a>
endwhile;
wp_reset_postdata();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment