0

I have a custom post type called Treatment.

From my understanding of WordPress, archive.php will always be used unless there is an archive-{posttype}.php.

For some reason the archive page is instead using landing-page.php (my front page template), and I can't seem to get it to use anything else. Even with archive.php and archive-treatment.php present.

Any ideas as to what's going on?

has_archive is set, and I'm definitely viewing the correct URL. If I set has_archive to false it becomes a 404 error.

Here is my register_custom_post_type() for Treatments:

function register_custom_post_type() {
    register_post_type( 'treatment', array(
        'labels' => array(
            'name'               => _x( 'Treatments', 'post type general name', 'nsc-treatments' ),
            'singular_name'      => _x( 'Treatment', 'post type singular name', 'nsc-treatments' ),
            'menu_name'          => _x( 'Treatments', 'admin menu', 'nsc-treatments' ),
            'name_admin_bar'     => _x( 'Treatment', 'add new on admin bar', 'nsc-treatments' ),
            'add_new'            => _x( 'Add New', 'treatment', 'nsc-treatments' ),
            'add_new_item'       => __( 'Add New Treatment', 'nsc-treatments' ),
            'new_item'           => __( 'New Treatment', 'nsc-treatments' ),
            'edit_item'          => __( 'Edit Treatment', 'nsc-treatments' ),
            'view_item'          => __( 'View Treatment', 'nsc-treatments' ),
            'all_items'          => __( 'All Treatments', 'nsc-treatments' ),
            'search_items'       => __( 'Search Treatments', 'nsc-treatments' ),
            'parent_item_colon'  => __( 'Parent Treatment:', 'nsc-treatments' ),
            'not_found'          => __( 'No treatment found.', 'nsc-treatments' ),
            'not_found_in_trash' => __( 'No treatment found in Trash.', 'nsc-treatments' ),
        ),

        // Frontend
        'has_archive'        => 'cosmetics/treatments',
        'public'             => false,
        'publicly_queryable' => false,

        // Admin
        'capability_type' => 'post',
        'menu_icon'     => 'dashicons-screenoptions',
        'menu_position' => 10,
        'query_var'     => true,
        'show_in_menu'  => true,
        'show_ui'       => true,
        'supports'      => array(
            'title',
            'author',
        ),
    ) );

I have also tried changing has_archive => 'cosmetics/treatments' to:

'has_archive'        => 'true',
'rewrite'            =>  array( 'slug' => 'cosmetics/treatments' ),

As I've seen in other answers relating to this topic.

The theme is based of Underscores with no changes to anything under the hood. Only added CSS, template parts and custom post types.

I have reset the permalinks after each change.

Any help is greatly appreciated, as I'm still rather new to Wordpress

6
  • i recreated your setup so far and it should work. can you show us your $args array for and the register_post_type part of your cod and the part where landing-page.php is called in your code (with context please)?
    – iantsch
    Mar 18 '16 at 17:37
  • Are you in minimal environment ?
    – Sumit
    Mar 19 '16 at 6:34
  • As it is, your question seems a support question. You must have some code in your web generating that behaviour, impossible to know where. Please, provide more information.
    – cybmeta
    Mar 19 '16 at 6:49
  • @iantsch I've updated the question with more detail. I do not directly call 'landing-page.php' in code, only select the template for my static front page using the Wordpress frontend
    – Solflux
    Mar 20 '16 at 13:12
  • your publicly_queryable and public flags are set to false. if you don't make your post_type publicly_queryable and public the front-end will ignore it. source: developer.wordpress.org
    – iantsch
    Mar 20 '16 at 14:02
0

In your register_post_type function you set your publicly_queryable and public flags to false. If you don't make your post_type publicly_queryable and public, the front-end will simply ignore it.

Source: developer.wordpress.org

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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