Skip Navigation

[Closed] display custom post without views.

This support ticket is created 11 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 2 replies, has 2 voices.

Last updated by Hrvoje.B1 11 years, 1 month ago.


I've created a custom post type called "slides" and I try to display the content in my header.
I could use views to do it but I also would like to know how to do it with PHP?

I'm using this code but it doesn't work :

<?php query_posts('post_type=slides&posts_per_page=4'); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

Thank you


Hi Benoit,

I have a similar code that works:

/** save the original query **/
$orig_query = $wp_query;
$args = array( 
    'post_type' => 'slides',
    'post_per_page' => 4 
$wp_query = new WP_Query($args);

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



** restore original query **/
$wp_query = $orig_query; wp_reset_query();

You can see it in action here hidden link
It's still in development so some design glitches may occour 😀

I hope this helps


Forgot to add - the $wp_query->the_post(); prepares the $post objects so You can use the the_post_thumbnail(), and other wp stuff there

The topic ‘[Closed] display custom post without views.’ is closed to new replies.