Sometime it is required to display data from Custom Post Type in PHP template file in WordPress. In my previous tutorial post, you have read How to create custom post type in WordPress using CPT UI. In this tutorial, you will see How to display CPT in WordPress using WP_Query.
In my previous tutorial, I have created a custom post type
testimonial_cpt
labelled as “Testimonials”. In this tutorial I am going to fetch the data from thistestimonial_cpt
. If you are beginner, then I will recommend to read my previous tutorial.
Let’s create a custom page template.
Create a PHP file with any name say testimonial.php
. Add the following comment lines at the top of this template file.
<?php /** **Template Name: Testimonial */
The above code display the simple list of title & description created in testimonial post type in previous article.
Here is the full source code:
Create a page in WordPress Page from dashboard and assign the above created template file from page attribute section. Now, publish and view the page.
View Comments
Great blog here! Also your web site loads up fast! Aura Arturo Daney