You need to first query your custom post.. then return it through the loop.
Something like this should work:
$args = array( 'post_type' => 'SLUG', 'posts_per_page' => 10 );
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
the_title();
echo '<div class="entry-content">';
the_content();
echo '</div>';
endwhile;
Just change “SLUG” to the actual slug you used for the custom post type.
You sir are my hero!!
I have already tried it like this:
<?php
if(is_single()) :
// Post args
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$arr_post_args = array(
'posts_per_page' => 10,
'post_type' => 'news',
'orderby' => 'date',
'order' => 'DESC',
'paged' => $paged
);
// Post Query
query_posts($arr_post_args);
endif;
?>
But it didn’t work. Your code works perfectly for me though. Thank you!!
🙂 My pleasure!
The code you are using above is an advanced form of querying the argument… but it doesn’t do anything to actually output the data.
You could combine both into something like this:
$args = array(
'posts_per_page' => 10,
'post_type' => 'news',
'orderby' => 'date',
'order' => 'DESC',
'paged' => $paged
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
the_title();
echo '<div class="entry-content">';
the_content();
echo '</div>';
endwhile;
That’ll give you a little advanced flexibility on how to query the custom posts.
Oh I see, this is even much better … just what I wanted.
Thank you so much, you were a great help!!
You bet!!
(Please mark your thread as “resolved” to help others’ in the future)
Happy blogging!!