I have created a custom post type in my functions.php:

function keyword_pages_init() {
    $args = array(
      'label' => 'Keywords',
        'public' => true,
        'show_ui' => true,
        'capability_type' => 'page',
        'hierarchical' => false,
        'rewrite' => array('slug' => 'keywords'),
        'query_var' => true,
        'menu_icon' => 'dashicons-admin-page',
        'supports' => array(
    register_post_type( 'keywords', $args );
add_action( 'init', 'keyword_pages_init' );

And this is the custom template page that I want to use for that custom post type pages:

Template Name: Single Section
Template Post Type: post, page, keywords
 * The template for displaying the single section.
 * This is the template that displays the home page by default.
 * Please note that this is the WordPress construct of pages and that
 * other "pages" on your WordPress site will use a different template.
 * @package WordPress
 * @subpackage xxx
 * @since xxx 1.0

get_header(); ?>

    // Include the page nav.
    get_template_part( 'nav-header', 'nav' );

    <main role="main" id="main" class="main-container">

        // Include the page nav.
        get_template_part( 'nav-keywords', 'nav' );

        $first_section = true;
        $first_sub = true;

        // Get post slug.
        $slug = $post->post_name;

        // Get post id.
        $post_id = $post->ID;

        // Prepare an empty array.
        $elements = array();

        <!-- section -->
            <div class="container section-container">

                // Include the related items.
                // http://keithdevon.com/passing-variables-to-get_template_part-in-wordpress/

                <?php if (count($elements) === 0) { ?>
                <p>No content found. </p>
                <?php } ?>



    // Include the page nav.
    get_template_part( 'nav-footer', 'nav' );

<?php get_footer();

But I get a 404 page when I created a custom page under that custom post type.

What else did I miss?

Read more here: Custom post type pages return 404 page?


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

Wordpress related questions and answers: