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 May 5 '18 at 15:27
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. – user7432810 May 5 '18 at 14:24

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.