0

I seem to go round and round in circles here, I think lack of vocabulary or not knowing what I'm searching for is causing me my problems.

I have a custom post type projects and have a taxonomy to reflect that.
When trying to add categories links from this post type in a menu, it links on the site as domain.com/category/custom_cat

Ideally, I would like the URL to read: domain.com/projects/custom_cat

Could someone please point me in the right direction.

Many thanks!

Edit:

I think i unfolded one problem and created another, I replaced:

 register_taxonomy( 'category', 'project', array( 'hierarchical' => true, 'label' => 'Project Categories', 'query_var' => true, 'rewrite' => true ) );

with

 register_taxonomy( 'projects', 'project', array( 'hierarchical' => true, 'label' => 'Project Categories', 'query_var' => true, 'rewrite' => true ) );

and created a category and assigned it to a project to test it out. It worked!

However, I have most of the site populated with the old category taxonomy. How would one suggest repairing the SQL so I can inherit the old category names to the new taxonomy?

0
1

You have to add a taxonomy category for your new custom post type such as

function mvli_customtype_category() {

    register_taxonomy(
        'customtype-category',
        'customtype',
        array(
            'label' => __( 'Category' ),
            'rewrite' => array( 'slug' => 'customtype-category' ),
            'hierarchical' => true,
        )
    );
}
add_action( 'init', 'mvli_customtype_category' );

And then you can easily open the link like this website.com/customtype-category/

let's say your category is named apple website.com/customtype-category/apple

Now enjoy this code and rename and replace it with your terms.

2
  • 1
    Hi, I think I resolved that element of the problem it was retaining the old categories that already exist under the old taxonomy. – Neilisin May 11 '18 at 11:31
  • Perfect. Glad you figured it out. :) – marvinpoo May 11 '18 at 11:32
1

So the answer was a combination of 2 things... as Marvinpoo said but also once changed to honour the existing categories i needed to update the term_taxonomy table in MySQL using the following query:

UPDATE `wp_term_taxonomy` SET `taxonomy` = REPLACE(`taxonomy`, 'category', 'projects')

22 rows were changed in my case and then everything worked silky smooth! :-D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.