skip to Main Content

I want to get_queried_object of parent to see does he have any parents. How can i get it?
I think that it should be something like this

$parent_id_of_current_category->get_queried_object()->parent;

2

Answers


  1. Chosen as BEST ANSWER
    $id = get_queried_object_id();
    $ancestors = get_ancestors($id,'product_cat');
    

    Here is the solution, to get all parent of post/taxonomy/page and so on. Just replace 'product_cat' with what you need


  2. Use get_term_by:

    $father_term_id = get_queried_object()->parent;
    
    $grandfather_term_id = get_term_by( 'term_taxonomy_id', $father_term_id )->parent;
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search