1

I'm new to WordPress but I would like to know how can one get a custom post type linked to 3 custom taxonomies. I have created a custom post type called "product" and created three custom taxonomies and linked them to the product post type. My aim is to make a product have category, brand and type..which are the three custom taxonomies I have created.

Here is my functions.php file. My goal is to come up with something like this where "Ved" is the category name, "Stuv" is the brand name, and "Braskaminer" is the type name of the product and lastly "stuv 16 H", "Hwam 2630" etc. are the respective products. I will really appreciate if I can get some guidance on how I can use WordPress functions to achieve this.

1

When registering a post type, always register your taxonomies using the taxonomies argument. If you do not, the taxonomies and post type will not be recognized as connected when using filters such as parse_query or pre_get_posts. This can lead to unexpected results and failures.

http://codex.wordpress.org/Function_Reference/register_post_type#Taxonomies

Your argument list for register_post_type needs to include:

'taxonomy' => array('ct1','ct2','ct3')

Your custom taxonomies have to be registered first.

Alternately, you can use register_taxonomy_for_object_type.

register_taxonomy_for_object_type( 'ct1', 'yourcpt' );
register_taxonomy_for_object_type( 'ct2', 'yourcpt' );
register_taxonomy_for_object_type( 'ct3', 'yourcpt' );

Again, your custom taxonomies have to be registered first.

  • Thanks for that hint. I have done that but to be honest like i said am a newbie to wordpress. Do you mind guiding me on how I will fetch the products with all those taxonomy their belong to. Will really appreciate that – Nyaga Kennedy Sep 10 '13 at 17:50

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.