Loop custom posts in wordpress

Loop custom posts in wordpress


$temp = $wp_query;

$wp_query = null;

$wp_query = new WP_Query();


if ($wp_query->have_posts()) : ?>

<?php while ($wp_query->have_posts()) : $wp_query->the_post(); ?>

<div class=”entry”>

<h2><a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a></h2>

<?php the_excerpt(); ?>


<?php endwhile; ?>

<div class=”navigation”>

<div class=”alignleft”><?php next_posts_link(‘&laquo; Older Entries’) ?></div>

<div class=”alignright”><?php previous_posts_link(‘Newer Entries &raquo;’) ?></div>


<?php $wp_query = null; ?>

<?php $wp_query = $temp;  ?>

<?php else : ?>

<h2>Not Found</h2>

<p>Sorry, but you are looking for something that isn’t here.</p>

<?php endif; ?>

Related Articles

Display the thumbnail of a custom field picture

we take the id picture of the custom field: $id_picture = get_post_meta( get_the_ID(),’image_1′ ,true ) $image1 = wp_get_attachment_image($id_picture, ‘thumbnail’);  

Hote notice and warnings on wordpress

in wp-config.php replace the line: define(‘WP_DEBUG’, false); or maybe you have: define(‘WP_DEBUG’, true); with the lines: ini_set(‘log_errors’,’On’); ini_set(‘display_errors’,’Off’); ini_set(‘error_reporting’, E_ALL

Tribe events sidebar widget list – increase number of events displayed

I wanted more than 10 events to be displayed. The file that need to be changed is: wp-content/plugins/the-events-calendar/src/admin-views/widget-admin-list.php at line 20