WordPress tutorials: Get posts outside loop

Wpsnipp – Custom fields are definitely very useful and are used on many WordPress-powered blogs. In this recipe, I’m going to show you how to easily get custom fields values outside the loop.Adding this PHP code to your wordpress theme will allow you to query and display posts outside of the loop. You can place this code in any location of your theme.

 

 

<?php
$feature_posts = get_posts('numberposts=10&orderby=post_name');
foreach($feature_posts as $post) : setup_postdata($post);
?>
<? the_title(); ?>
<? the_content(); ?>
<?php
endforeach;
?>

Be Sociable, Share!

Leave a comment