0

So I have used the CPT plugin to create a custom post type called Works. The slug I have set is proctor-work and I have created a template called archive-proctor-work.php. I cannot get this to show on http://proctordevelop.wpengine.com/proctor-work, it just keeps showing the 404 page. I have flushed permalinks. All of the files referenced in the archive page have been added to the site in the child theme.

I also have added a registration to functions.php. (see below) Can anyone help?

here is the code for the archive page:

<?php
    /**
     * The template for displaying Our Work
     *
     * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
     *
     */
    
    get_header();
    ?>
    
        <section id="primary" class="content-area post-listing -listing">
            <main id="main" class="site-main">
    
            <?php if ( have_posts() ) : ?>
                
    
                <?php include 'our-work-filters.php'; ?>
    
                <div class="center container">
                <?php
                /* Start the Loop */
                while ( have_posts() ) :
                    the_post();
    
                    /*
                     * Include the Post-Type-specific template for the content.
                     * If you want to override this in a child theme, then include a file
                     * called content-___.php (where ___ is the Post Type name) and that will be used instead.
                     */
                    get_template_part( 'proctor_content', get_post_type() );
    
                endwhile;
            ?>
                <!-- <div class="pagination"><?php wpex_pagination(); ?></div> -->
            <?php
            else :
    
                get_template_part( 'proctor_content', 'none' );
    
            endif;
            ?>
        </div>
            </main><!-- #main -->
        </div><!-- #primary -->
    
    <?php
    get_footer();

Registration code


function wporg_custom_post_type() {
    register_post_type('proctor-work',
        array(
            'labels'      => array(
                'name'          => __( 'Works', 'textdomain' ),
                'singular_name' => __( 'Work', 'textdomain' ),
            ),
            'public'      => true,
            'has_archive' => true,
            'rewrite'     => array( 'slug' => 'proctor-work' ), // my custom slug
        )
    );
}  

1 Answer 1

0

While registering custom_post_type use this parameters too.

'publicly_queryable' => true,

Then it should be look like this.

function wporg_custom_post_type() {
register_post_type('proctor-work',
    array(
        'labels'      => array(
            'name'          => __( 'Works', 'textdomain' ),
            'singular_name' => __( 'Work', 'textdomain' ),
        ),
        'public'      => true,
        'has_archive' => true,
        'rewrite'     => array( 'slug' => 'proctor-work' ), // my custom slug
        'publicly_queryable'    => true
    )
);

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.