• I would like to have a custom permalink for a cpt sections like: sections\sections_id.
    When I go to settings -> permalinks and select the PLAIN version, then my normal posts show the normal setting: \?p=post_id whereas my cpt sections have a permalink of the following format: ?sections=section-name

    Modifying this format is supposed to be done when registering the cpt under the rewrite tag: 'rewrite' => array('slug' => '', 'with_front' => false),

    However, regardless as to what I fill in for slug, and regardless as to how many times I exercise the Flush-Rewrite ritual by visiting settings/permalinks, my permalink stubbornly remains at the same default format: ?sections=section-name
    So whilst I expect the following:
    'rewrite' => array('slug' => 'something', 'with_front' => false), or
    'rewrite' => array('slug' => 'something', 'with_front' => true),
    to render a permalink of the format: \something\section-name or perhaps \something?sections=section-name no change occurs.

    The only time when it changes is when I select a different permalink structure under settings -> permalink, such as Post Name. When selecting this, now my permalink for the cpt is ‘\sections\section-name’.

    Now again, regardless as to what I may change in
    'rewrite' => array('slug' => '', 'with_front' => false),
    and regardless as to how many times I refresh that permalink page under settings, or even save another selection and then go back to Post Name selection and save that, my permalink for my cpt simply does not want to change.

    This is the code I use to register a custom post type:

    add_action( 'init', 'create_section_type' );
    function create_section_type() {
    	$labels = array(
          'name'                => _x( 'Sections', 'Post Type General Name', 'FoundationPress' ),
          'singular_name'       => _x( 'Section', 'Post Type Singular Name', 'FoundationPress' ),
          'menu_name'           => __( 'Sections', 'FoundationPress' ),
          'parent_item_colon'   => __( 'Parent Section', 'FoundationPress' ),
          'all_items'           => __( 'All Sections', 'FoundationPress' ),
          'view_item'           => __( 'View Section', 'FoundationPress' ),
          'add_new_item'        => __( 'Add New Section', 'FoundationPress' ),
          'add_new'             => __( 'Add New', 'FoundationPress' ),
          'edit_item'           => __( 'Edit Section', 'FoundationPress' ),
          'update_item'         => __( 'Update Section', 'FoundationPress' ),
          'search_items'        => __( 'Search Section', 'FoundationPress' ),
          'not_found'           => __( 'Not Found', 'FoundationPress' ),
          'not_found_in_trash'  => __( 'Not found in Trash', 'FoundationPress'
         ),
      );
    
      register_post_type( 'sections',
        array(
          'labels' => $labels,
          'supports' => array('title'),
          'public' => true,
          'has_archive' => true,
          'rewrite' => array('slug' => '', 'with_front' => false),
        )
      );
    }

    Besides this, I use CMB2 to set extra custom fields.

    What am I overlooking here?

    Thanks.

  • The topic ‘Custom Permalink For Custom Post Type’ is closed to new replies.