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.

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

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

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.