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(
    register_post_type('apps', $args);

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

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


  • Please refer at once wpexplorer.com/post-type-404-error – Pratik Patel Oct 17 '18 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 Oct 17 '18 at 9:32
  • have you try 'has_archive' => true, ? – Pratik Patel Oct 17 '18 at 9:33
  • yes, didn't work – Zeeshan Sultan Oct 17 '18 at 9:35
  • Shouldn't the rewrite slug be without the trailing slash? – Pim Oct 17 '18 at 9:52

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

💡 Bonus tip: You should avoid using flush_rewrite_rules() there, it's quite heavy and affects performance. You should ONLY use it when modifying rewrite_rules outside of register_post_type(), usually in plugin or theme activation/deactivation hooks.

| improve this answer | |
  • Didn't work in my case. Tried. – Zeeshan Sultan Oct 17 '18 at 19:31

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.