Support » Fixing WordPress » custom post types – no permalinks or 404

  • i am at my wits end on this. i am simply trying to get simple posts – of a custom post type – to show up on the front end of the site with a pretty url. i have all the basics (.htaccess, permalink settings, etc). i am not new to wordpress, but this is the first time i am using custom post types. please bear with me, i will try to provide lots of info.

    i have my permalink settings set to use custom structure of “/%category%/%postname%/”.

    i installed a brand new copy of wordpress (4.9.4). no plugins enabled. i created 50 categories, one for each state in the u.s. the slugs for those are the state name, so alaska permalink is all good.

    i installed a super-simple custom plugin that does nothing but create a custom post type (city). i will paste that code below.

    i create a post of type city (say, “anchorage”), with the slug “anchorage-ak”. by default, when i edit the post in wp-admin, the permalink for the post is:

    i understand that is the default behavior for custom post types, but i need the url to be:

    so, i added a rewrite option to the plugin’s call to register_post_type() like so:

    ‘rewrite’ => array(‘slug’ => ‘%category%’),

    when i edit the post now, there is literally NO PERMALINK that shows below the post title. the label “Permalink:” is there, followed by the “edit” button.

    so, i installed a permalink plugin “permalink manager lite”. (i have tried several, that one seems to come the closest to doing what i want.) i activated that plugin, and set the permastructure for city posts to “%category%/%postname%”. when i edit the post now, i see the permalink i want:

    when i try to access that url from the front end – i type it into the browser address bar – the url changes (a redirection that i don’t understand) to:

    and of course i get a 404. i get the same result if i use this url instead (redirect and 404)

    if i remove the
    ‘rewrite’ => array(‘slug’ => ‘%category%’),

    from the register_post_type() call, the permalink goes back to

    and if i disable the plugin, when i edit the post there is no permalink.

    UPDATE: when i turn off the permalink manager lite setting for “canonical redirect”, then the redirect to urls including “%category%” goes away. instead, if i include the “rewrite” stuff in the register_post_type() call, there is no redirect, and i get a 404 on the url if i remove the redirect stuff from the register_post_type() call, then the permalink goes back to

    i know i must be missing something obvious. it can’t be that difficult to get the permalinks i want. or can it?

    can anyone help?

    thanks VERY much in advance.

    here is the code for the plugin:

    add_action( ‘init’, ‘create_post_types’ );

    function create_post_types()
    register_post_type( ‘city’,
    ‘labels’ => array(
    ‘name’ => __( ‘Cities’ ),
    ‘singular_name’ => __( ‘City’ )
    ‘description’ => __(‘City Posts represent a single city within a given state’),
    ‘public’ => true,
    ‘has_archive’ => false,
    ‘rewrite’ => array(‘slug’ => ‘%category%’),
    ‘menu_position’ => 5,
    ‘hierarchical’ => false,
    ‘supports’ => array(‘title’, ‘editor’, ‘author’, ‘trackbacks’, ‘custom_fields’, ‘comments’),
    ‘taxonomies’ => array(‘category’, ‘post_tag’),

    • This topic was modified 1 year, 7 months ago by  laz0rama.
    • This topic was modified 1 year, 7 months ago by  laz0rama.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘custom post types – no permalinks or 404’ is closed to new replies.