I have a taxonomy called schedule_day_taxonomy
add_action( 'init', 'schedule_day_tax_func' );
function schedule_day_tax_func() {
register_taxonomy(
'schedule_day_taxonomy',
'schedule',
array(
'hierarchical' => true,
'label' => 'Day',
'query_var' => true,
'orderby' => 'ID', /*
)
);
}
and this taxonomy
is assigned to a certain custom post type only.. called schedule
add_action( 'init', 'schedule_func' );
function schedule_func(){
register_post_type('schedule', array(
'label' => 'TV schedule',
'show_ui' => true,
'supports' => array('title', 'thumbnail'),
'public' => true,
'publicly_queryable' => true,
'rewrite' => array( 'slug' => 'show-schedule' ),
'labels' => array (
'name' => 'TV schedule',
'singular_name' => 'TV schedule',
'menu_name' => 'TV Schedules'
),
) );
}
Now I want to get post by terms
created under the taxonomy schedule_day_taxonomy
which is assigned only for the custom post type schedule
I've created two terms monday
and tuesday
I am trying to get all the posts if it is under the term tuesday
. So I've tried following code:
<ul id="home-sche-list">
<?php
$args = array( 'post_type' => 'schedule', 'posts_per_page' => 15, 'tax_query' => array(
array(
'taxonomy' => 'schedule_day_taxonomy',
'field' => 'tuesday',
'terms' => 'tuesday'
)
)
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
$image_id = get_post_thumbnail_id();
$image_url = wp_get_attachment_image_src($image_id,'schedule_home_page_thumb', true);
$terms = get_the_terms( $post->ID, 'schedule_taxonomy' );
?>
<li>
<a href="<?php the_permalink(); ?>" target="_blank" class="wrapper-container">
<div class="sche-thumb-con">
<span>
<img src="<?php echo $image_url[0]; ?>" class="video-thumb hoverZoomLink" alt=""/>
<div class="new-cat">
<?php
foreach($terms as $term) {
echo $term->name;
} ?>
</div>
</span>
</div>
<div class="sche-txt-wrapper">
<div class="schedule-prog"><?php the_title(); ?></div>
<div class="schedule-time evening">
<?php
$terms = get_the_terms( $post->ID, 'schedule_time_taxonomy' );
foreach($terms as $term) {
echo $term->name;
}
?>
</div>
</div>
</a>
</li>
<?php endwhile; ?>
</ul>
But I am getting no posts displayed. I have a post which is assigned to the term tuesday
.
Admin address bar
What I am doing wrong? Will it affect if I assign this post to two more taxonomies (custom)? I have two more taxonomies and those are assigned to this post.