single-{post-type}.php is not working in wordpress

My single-{post-type}.php is not working. This is custom post type based on recent work or projects. when i click the permalink link it don’t go to single-projects.php, it goes to home page or index page. Any solution please.

Register post type:

 //Custom post for Recent work
    function projects_post_type() {

             register_post_type( 'projects',
     array(
    'labels' => array(
     'name' => __( 'Recent Work' ),
     'singular_name' => __( 'Recent Work' ),
     'add_new' => __( 'Add New' ),
     'add_new_item' => __( 'Add New work' ),
     'edit_item' => __( 'Edit work' ),
     'new_item' => __( 'New work' ),
     'view_item' => __( 'View work' ),
     'not_found' => __( 'Sorry, we couldn't find the work you are looking for.' )
                ),

    'public' => true,
    'publicly_queryable' => false,
    'exclude_from_search' => true,
    'menu_position' => 14,
    'has_archive' => false,
    'hierarchical' => false, 
    'capability_type' => 'page',
    'rewrite' => array( 'slug' => 'projects' ),
   'supports' => array('title')
            )
        );

             register_taxonomy(
         'filtering_category',
         'projects',
     array (
         'labels' => array(
         'name' => 'Filter Category',
         'add_new_item' => ' Add New Filter Category'
            ),
         'hierarchical' => true,
         'show_admin_column' => true
              ) );

    }

add_action( 'init', 'projects_post_type' );

Portfolio Page:

         <?php

                            $args = array(
                            'post_type' => 'projects',
                            'posts_per_page' => '-1',
                              );
                             // the query
                             $query = new WP_Query( $args );
                              // The Loop   
                             if ( $query->have_posts() )  ?>
               <?php while ( $query->have_posts() ) : $query->the_post() ; ?>

                    <div class="portfolio logo" data-cat="logo">
                        <div class="portfolio-wrapper">
                            <div class="portfolio-hover">
                                <div class="image-caption">

<a href="<?php echo get_post_meta(get_the_ID(), 'work_photo', true); ?>" class="label magnefig label-info icon" data-toggle="tooltip" data-placement="left" title="Zoom"><i class="fa fa-eye"></i></a>

<a href="<?php the_permalink();  ?>" class="label label-info icon" data-toggle="tooltip" data-placement="top" title="Details"><i class="fa fa-link"></i></a>
                                    </a>

                            </div>
 <img src="<?php echo get_post_meta(get_the_ID(), 'work_photo', true); ?>" alt="" />

                        </div>
                    </div>
                </div>


             <?php endwhile;   ?>

Read more here: single-{post-type}.php is not working in wordpress

Leave a Reply

Your email address will not be published. Required fields are marked *