0

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
                   unset($term);
                  } }else{
                     echo 'All Interview';  

                  } ?></a>

i get name but notice shows every time.

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

1 Answer 1

-1

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

1
  • 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.