Search code examples
wordpresswordpress-shortcode

How to display custom Post in WordPress?


I am not sure how to use custom posts in Wordpress. I have tried them with the plugin's but, the problem here is when I have deactivated plugins which are not useful then the related posts are going down. I want to make them available. Is there any easy way to post them?


Solution

  • The problem with using a plugin is that your custom post types will disappear when the plugin is deactivated. Any data you have in those custom post types will still be there ,but your custom type will be unregistered and will not be accessible from the admin area.

    You can use below code for the custom posts:

    <?php
    $args = array('post_type' => 'blog', 'post_per_page' => 10);
    $loop = new WP_Query($args); ?>
    <?php while ($loop->have_posts()): $loop->the_post(); ?>
        <?php the_title(); // echo get_the_title() ?>
        <?php the_content(); // echo get_the_content() ?>
    <?php endwhile; ?>
    

    Reference :

    https://www.wpbeginner.com/wp-tutorials/how-to-create-custom-post-types-in-wordpress/