WordPress Custom Post Type Single Page

I have created a custom post type in WordPress with CPT UI named eggs.

In the file named eggs.php I put this code:

Read More
<?php
$args = array('post_type' => 'eggs');
$query = new WP_Query($args);
?>

<?php if ($query->have_posts() ) : while( $query->have_posts() ) : $query->the_post(); ?>
      <a href="<?php the_permalink(); ?>" Go to Eggs Single Page</a>
<?php endwhile; endif; wp_reset_postdata(); ?>

Now I have created a file named single-eggs.php and when I click on the permalink it redirects me on a page where it says “Sorry, no posts matchef your criteria.” . It doesn’t go to the page single-eggs.php as I want.

EDIT: Currently I am using Custom Post Type UI plugin by WebDevStudios.
When I’m using the Types plugin from OnTheGoSystems it finds the single-template.php. Is it something wrong with the plugin maybe?

Related posts

1 comment

  1. Instead of using a plugin to register your Custom Post Types, you could simply use register_post_type function to register your own CPT:

    function my_cpt_eggs(){
        $labels = array(
            'name'                          => __( 'eggs' ),
            'singular_name'                 => __( 'egg' ),
            'menu_name'                     => __( 'eggs' ),
            'all_items'                     => __( 'All eggs' ),
            'add_new'                       => __( 'Add egg' ),
            'add_new_item'                  => __( 'Add New egg' ),
            'edit_item'                     => __( 'Edit egg' ),
            'new_item'                      => __( 'New egg' ),
            'view_item'                     => __( 'View egg' ),
            'search_items'                  => __( 'Search eggs' ),
            'not_found'                     => __( 'Not found' ),
            'not_found_in_trash'            => __( 'Not found in Trash' )
        );
        $args = array(
            'label'                         => __( 'eggs' ),
            'labels'                        => $labels,
            'description'                   => __( 'egg items' ),
            'public'                        => true,
                'exclude_from_search'       => false,
                'publicly_queryable'        => true,
                'show_ui'                   => true,
                'show_in_nav_menus'         => true,
                    'show_in_menu'          => true,
                        'show_in_admin_bar' => true,
                        'menu_position'     => 10,
            'capability_type'               => 'post',
            'map_meta_cap'                  => true,
            'hierarchical'                  => false,
            'supports'                      => array( 'title', 'editor', 'excerpt', 'thumbnail' ),
            'taxonomies'                    => array(),
            'has_archive'                   => true,
            'query_var'                     => true,
            'can_export'                    => true,
        );
    }
    add_action( 'init', 'my_cpt_eggs' );
    

    Put the above snippet in your functions.php file.

    After that you may create your single-eggs.php and everything will be OK.

    Keep in mind that you may need to refresh the rewrite rules. To do so, you should go to

    WordPress Admin > Settings > Permalinks
    

    and simply hit the Save settings button at the bottom.

Comments are closed.