I have managed to get all parent categories from Woocommerce with this function

$terms = get_terms( array(
    'taxonomy' => 'product_cat',
    'hide_empty' => false,
    'parent'    => 0
) );

But I haven't managed to do the same with WP_Query. Now I have 2 questions:

  1. How can I do the same - getting a list of categories from Woocommerce - with WQ_Query
  2. Is it recommended to use WP_Query over get_terms?


  • 1
    WP_Query is for querying posts and only returns post objects
    – Milo
    Commented May 5, 2018 at 15:27

1 Answer 1

foreach($category_detail as $cd)

try now this code

  • I need to get a list of all/parent categories not a category for the_post. Commented May 5, 2018 at 14:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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