In order to get posts from our custom post type you can follow the loop that is shown below by replacing the post type with your custom post type.
$query = array(
'post_type'=> 'your_custom_post_type',
'orderby' => 'ID',
'post_status' => 'publish',
'order' => 'DESC',
'posts_per_page' => -1
);
$result = new WP_Query( $query );
if ( $result-> have_posts() ) : ?>
<?php while ( $result->have_posts() ) : $result->the_post(); ?>
<?php
// to get the post featured image as thumbnail
the_post_thumbnail('thumbnail');
?>
<?php
// to get the Post title
the_title();
?>
<?php
// to get the post content
the_content();
?>
<?php endwhile; ?>
<?php endif; wp_reset_postdata(); ?>
This query will get the posts that are created under your custom post type and i have displayed the post featured image, post title and the post content.
$query = array(
'post_type'=> 'your_custom_post_type',
'orderby' => 'ID',
'post_status' => 'publish',
'order' => 'DESC',
'posts_per_page' => -1
);
$result = new WP_Query( $query );
if ( $result-> have_posts() ) : ?>
<?php while ( $result->have_posts() ) : $result->the_post(); ?>
<?php
// to get the post featured image as thumbnail
the_post_thumbnail('thumbnail');
?>
<?php
// to get the Post title
the_title();
?>
<?php
// to get the post content
the_content();
?>
<?php endwhile; ?>
<?php endif; wp_reset_postdata(); ?>
This query will get the posts that are created under your custom post type and i have displayed the post featured image, post title and the post content.
No comments:
Post a Comment