简体   繁体   中英

Wordpress Costum Post Type - ACF in URL

I have some problem that I need help in them -

I register costum post type - is slug is "project"

But I need to make 3 categories (with ACF) and make url changed due to it

category1 = http://www.example.com/mycaturl/nameoftitle

category2 = http://www.example.com/othercat/nameoftitle

category3 = http://www.example.com/customedit/nameoftitle

How can I make it without plugins...?

Thanks for helpers :)

Tested and verified:

I am writting in steps to make it clear:

  1. Make sure when you registered your custom post type rewrite for more: register custom post type

'rewrite' => array('slug' => '/%project_categories%','with_front' => FALSE),

  1. Then register your taxonomies project_categories

You need to register custom taxonomy project_categories for this custom ( project ) post type. register_taxonomy please read here for more

function project_taxonomy() {  
    register_taxonomy(  
        'project_categories',  //The name of the taxonomy. Name should be in slug form (must not contain capital letters or spaces). 
        'project',        //post type name
        array(  
            'hierarchical' => true,  
            'label' => 'project store',  //Display name
            'query_var' => true,
            'rewrite' => array(
                'slug' => 'project', // This controls the base slug that will display before each term
                'with_front' => false //  Don't display the category base before 
            )
        )  
    );  
}  
add_action( 'init', 'project_taxonomy');
  1. Last make, your post type liks filters.

     function filter_post_type_link($link, $post) { if ($post->post_type != 'project') return $link; if ($cats = get_the_terms($post->ID, 'project_categories')) $link = str_replace('%project_categories%', array_pop($cats)->slug, $link); return $link; } add_filter('post_type_link', 'filter_post_type_link', 10, 2); 

Note: if you see post not found error. then change your permalink settings to default and save changes. And again set permalink to Post name and it will work.

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