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.
$post
object is not set unless you callthe_post()
function.