简体   繁体   中英

Custom Post Type Slug Rewrite Issues

To put a long story short, I'm trying to get the custom post type category to show where it says 'project-item' as you can see HERE

I presume it has something to do with the way I've registered the custom post type such as in this code:

<?php
add_action( 'init', 'register_posts' );
function register_posts() {

    register_post_type( 'team_post',
        array(
            'labels' => array(
                'name' => __( "Team" ,"um_lang"),
                'singular_name' => __( "Team" ,"um_lang")
            ),
            'public' => true,
            'has_archive' => true,              
            'rewrite' => array('slug' => "project_item", 'with_front' => TRUE),
            'supports' => array('title','editor','thumbnail','page-attributes')             
        )
    );

    register_post_type( 'project_post',
        array(
            'labels' => array(
                'name' => __( "Projects","um_lang"),
                'singular_name' => __( "Project" ,"um_lang")
            ),
            'public' => true,
            'has_archive' => true,              
            'rewrite' => array('slug' => "project_item", 'with_front' => TRUE),
            'supports' => array('title','editor','thumbnail','page-attributes')             
        )
    );

    register_taxonomy('project_category',array (
      0 => 'project_post',
    ),array( 'hierarchical' => true, 'label' => __('Projects Category',"um_lang"),'show_ui' => true,'query_var' => true,'singular_label' => __('Projects Category',"um_lang")) );

}
?>

Try this:

global $wp_rewrite;
$movies_structure = '/movies/%year%/%monthnum%/%day%/%movies%';
$wp_rewrite->add_rewrite_tag("%movies%", '([^/]+)', "movies=");
$wp_rewrite->add_permastruct('movies', $movies_structure, false);

return link:

domain.com/movies/movie_name

This tells wordpress to insert the text project_item into the slug, which is what is happening:

'rewrite' => array('slug' => "project_item", 'with_front' => TRUE)

And this says to insert the value of project_item:

'rewrite' => array('slug' => "%project_item%", 'with_front' => TRUE)

I figured it out. I installed this plugin: https://wordpress.org/plugins/custom-post-type-permalinks/

Then instead of using %categories% (Which didn't work) I used the specific custom post type category name (which was %project_category%)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM