I want to make single page for my custom post type but my method didn’t work.
I’ve created custom post type in this way:

    function portfolio(){
    $args = array(
        'public' => true,
        'label' => __('Portfolio'),
        'supports' => array('title', 'editor', 'thumbnail', 'custom-fields'));
    register_post_type('portfolio', $args);
    register_taxonomy('portfolio', 'portfolio');
}
add_action('init', 'portfolio');

I’ve made an query to display all items:

<?php  
        // The Query
        $the_query = new WP_Query( array( 'post_type' => 'portfolio', 'orderby' => 'date', 'order' => 'DESC', 'posts_per_page'=>-1 ) );
        // The Loop
        while ( $the_query->have_posts() ) : $the_query->the_post();                                        
            $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id ( $the_query->ID ), 'thumbnail' );
        ?> 
            <a href="<?php the_permalink(); ?>" class="col-md-4 item-portfolio">
              <img src="<?php echo $thumbnail[0]; ?>" alt="">
              <h4><?php the_title(); ?></h4>
              <p><?php echo get_post_meta( $post->ID, 'subtitle', true ); ?></p>
            </a>
        <?php endwhile; ?>

And I’ve created single-portfolio.php file but when I go in single item I have index.php instead of single-portfolio.php template. Where I’ve made a mistake? Thanks for help.

Read more here: Create custom post type single page


Solution:

If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Related Wordpress search:

, , , , ,

Wordpress related questions and answers: