$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>permalinks - Custom post type slug 404|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

permalinks - Custom post type slug 404

matteradmin12PV0评论

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

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far