i created a custom post type interview for that i also created custom post taxonomy interview_category and that custom taxonomy have some terms like students, teachers and some more. i trying to get the name of terms inside archive-interview.php but it show notice like undefined variable post and trying to get property of non-object. my code inside archive-interview is:

<?php if(have_posts()): 
        // $tax = $wp_query->get_queried_object();?>
        <section class="interview_main_wrapper">
            <div class="interview_head  dropdown">
                <button class="black-btn" type="button">
                  <a id="dropdownMenu1" class="auto_drop" data-toggle="dropdown">
                  <?php   // Get terms for post
                   $terms = get_the_terms( $post->ID , 'dastak_interview_category' );
                   // Loop over each item since it's an array
                   if ( $terms != null ){
                   foreach( $terms as $term ) {
                   // Print the name method from $term which is an OBJECT
                   print $term->slug ;
                   // Get rid of the other data stored in the object, since it's not needed
                  } }else{
                     echo 'All Interview';  

                  } ?></a>

i get name but notice shows every time.

  • the $post object is not set unless you call the_post() function.
    – Sisir
    Commented Dec 26, 2014 at 6:54

1 Answer 1


If you are using a custom loop. Please use $query->post to get the post object.

  • May you please elaborate your answer? Commented Sep 13, 2016 at 3:05

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.