permalinks - Custom post type slug 404

admin2025-06-07  23

I have created a custom post type

public function register_post_types() {
    $args = array(
        'labels' => array(
            'name' => 'Android Apps',
            'singular_name' => 'Android App',
            'add_new' => 'Add New App',
            'add_new_item' => 'Add New App',
            'edit_item' => 'Edit App',
            'new_item' => 'New App',
            'view_item' => 'View App',
            'search_item' => 'Search App',
            'not_found' => 'No Apps Found',
            'not_found_in_trash' => 'No Apps Found in Trash'
        ),
        'query_var' => 'apps',
        'rewrite' => array(
            'slug' => 'apps',
        ),
        'public' => true,
        'has_archive' => true,
        'menu_position' => 5,
        'menu_icon' => admin_url(). 'images/media-button-video.gif', //Icon url
        'supports' => array(
            'title',
            'thumbnail',
            'editor',
        )
    );
    register_post_type('apps', $args);
    flush_rewrite_rules();
}

The posts give a 404 on this style of permalinks http://site/apps/flashlight

Although they work fine on plain permalinks http://site/?apps=flashlight

I have created a custom post type

public function register_post_types() {
    $args = array(
        'labels' => array(
            'name' => 'Android Apps',
            'singular_name' => 'Android App',
            'add_new' => 'Add New App',
            'add_new_item' => 'Add New App',
            'edit_item' => 'Edit App',
            'new_item' => 'New App',
            'view_item' => 'View App',
            'search_item' => 'Search App',
            'not_found' => 'No Apps Found',
            'not_found_in_trash' => 'No Apps Found in Trash'
        ),
        'query_var' => 'apps',
        'rewrite' => array(
            'slug' => 'apps',
        ),
        'public' => true,
        'has_archive' => true,
        'menu_position' => 5,
        'menu_icon' => admin_url(). 'images/media-button-video.gif', //Icon url
        'supports' => array(
            'title',
            'thumbnail',
            'editor',
        )
    );
    register_post_type('apps', $args);
    flush_rewrite_rules();
}

The posts give a 404 on this style of permalinks http://site/apps/flashlight

Although they work fine on plain permalinks http://site/?apps=flashlight

Share Improve this question edited Oct 17, 2018 at 10:21 Zeeshan Sultan asked Oct 17, 2018 at 9:18 Zeeshan SultanZeeshan Sultan 14 bronze badges 10
  • Please refer at once wpexplorer/post-type-404-error – Pratik Patel Commented Oct 17, 2018 at 9:30
  • @PratikPatel Hi i have checked all the given fixes as you can see from the code i am flushing rewrite rules. This is the only apps slug on a fresh wp install so no conflicts .htaccess is there it's just not working with SEO friendly permalinks which are enabled by default. How to make it work? – Zeeshan Sultan Commented Oct 17, 2018 at 9:32
  • have you try 'has_archive' => true, ? – Pratik Patel Commented Oct 17, 2018 at 9:33
  • yes, didn't work – Zeeshan Sultan Commented Oct 17, 2018 at 9:35
  • Shouldn't the rewrite slug be without the trailing slash? – Pim Commented Oct 17, 2018 at 9:52
 |  Show 5 more comments

1 Answer 1

Reset to default 1

You are missing with_front in rewrite which is true by default. Change it to something like this

'rewrite' => array(
    'slug'          => 'apps',
    'with_front'    => false,
)

See the docs

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749255102a317653.html

最新回复(0)