Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 210725

issue with permalink structure for custom post type

$
0
0

Replies: 0

I have an issue with the permalink structure for a custom post type I’m trying to register.

I set the blog page in admin to my “news” page and i want my regular posts slug to look like this:

site.dev/news/test-post

so i set my permalink structure in admin like this:

site.dev/news/%postname%/

now I’m trying to register a custom post type, but i can’t seem to get the slug i want for the new post type.

i registered my post type like this

function my_custom_posttypes() {

    $labels = array(
        'name'               => 'Testimonials',
        'singular_name'      => 'Testimonial',
        'menu_name'          => 'Testimonials',
        'name_admin_bar'     => 'Testimonial',
        'add_new'            => 'Add New',
        'add_new_item'       => 'Add New Testimonial',
        'new_item'           => 'New Testimonial',
        'edit_item'          => 'Edit Testimonial',
        'view_item'          => 'View Testimonial',
        'all_items'          => 'All Testimonials',
        'search_items'       => 'Search Testimonials',
        'parent_item_colon'  => 'Parent Testimonials:',
        'not_found'          => 'No testimonials found.',
        'not_found_in_trash' => 'No testimonials found in Trash.',
    );

    $args = array(
        'labels'             => $labels,
        'public'             => true,
        'publicly_queryable' => true,
        'show_ui'            => true,
        'show_in_menu'       => true,
        'menu_icon'          => 'dashicons-id-alt',
        'query_var'          => true,
        'rewrite'            => array( 'slug' => 'testimonials' ),
        'capability_type'    => 'post',
        'has_archive'        => true,
        'hierarchical'       => false,
        'menu_position'      => 5,
        'supports'           => array( 'title', 'editor', 'thumbnail' )
    );
    register_post_type( 'testimonial', $args );
}
add_action( 'init', 'my_custom_posttypes' );

// Flush rewrite rules to add "testimonial" as a permalink slug
function my_rewrite_flush() {
    my_custom_posttypes();
    flush_rewrite_rules();
}
register_activation_hook( __FILE__, 'my_rewrite_flush' );

and i want the slug for my new custom post type to look like this:

site.dev/testimonials/test-testimonial

But i get:

site.dev/news/testimonials/test-testimonials

it seems that i either get the custom post type slug right by taking out the /news/ part of my permalink setting, but then again i don’t get the slug i want for my regular posts.

Anyone have a decent solution to this?


Viewing all articles
Browse latest Browse all 210725

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>