Skip to content
Advertisement

List custom post types with custom taxonomy category assigned to them

I have a custom post type called products and custom taxonomy called product-category. Now I need to list all the posts from this product post type which have product-category assigned to them. I thought something like this could work, but no luck. Could anyone point me in the right direction, please?! Really appreciate your help!

enter image description here

JavaScript

Advertisement

Answer

You might need to add the relation to your args.

JavaScript

Also, check:

  • Is the post type spelled correctly (i.e. Are you sure it’s products and not product?)
  • In your first query you have product_category but in your second query you have product-category. Should it be a hyphen or an underscore?
  • Is the value returned by $category valid?
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement