I have custom post type Named Trips , Taxonomy > Destination , Region Activity Etc.
Region Terms are , Annapurna , Everest etc. Activity Terms are trek, hiking, tours etc.
I made an archive template called taxonomy-region.php to show all activities under Region. But it should show all activities inside region template categorically but its not working properly.
Here is my code for taxonomy-region.php
<?php
/**
* Template Name: Region
*
* @package WordPress
* @subpackage Twenty_Fourteen
* @since Twenty Fourteen 1.0
*/
get_header();
$custom_post_id = get_the_ID();
?>
<style type="text/css">
section.country-bg {
height: 555px;
}
</style>
<?php
$taxonomyslug = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
$term = get_queried_object();
$image = get_field('region_taxonomy_image', $term);
$description = get_field('region_taxonomy_description', $term);
?>
<section class="country-bg" style="background:url(<?php echo $image ?>);background-size:cover;
background-repeat: no-repeat;">
</section>
<section class="main-sec">
<div class="container">
<div class="main-wrap">
<div class="row">
<div class="col-lg-12 col-md-12 col-sm-12">
<div class="countryabout-text">
<?php
if ( function_exists('yoast_breadcrumb') ) {
yoast_breadcrumb( '</p><p id="breadcrumbs">','</p><p>' );
}
?>
<h1><?php echo $taxonomyslug->name; ?></h1>
<?php echo $description; ?>
</div>
</div>
</div>
<div class="row countrysec">
<?php
$args = array('post_type' => 'trip',
'tax_query' => array(
array(
'taxonomy' =>'region',
'field' => 'slug',
'terms' => $taxonomyslug->slug,
),
),
);
$loop = new WP_Query($args);
if($loop->have_posts()) {
while($loop->have_posts()) : $loop->the_post();
$term_list[] = wp_get_post_terms($post->ID, 'activity', array('parent' => 0, "fields" => "all"));
endwhile;
$ss='';
foreach ($term_list as $value) {
$ss.=($value[0]->name).",";
}
$ss=explode(",",$ss);
$ss1=array_values(array_filter(array_unique($ss)));
$cc=count($ss1);
for($l=0;$l<$cc;$l++){
?>
<div class="col-lg-12 col-md-12 col-sm-12">
<h2 class="country-category">
<span class="heading-title"><?php echo $ss1[$l];?></span>
</h2>
</div>
<?php
$args = array('post_type' => 'trip',
'tax_query' => array(
array(
'taxonomy' =>'region',
'field' => 'slug',
'terms' => $taxonomyslug->slug,
),
),
);
$loop = new WP_Query($args);
while($loop->have_posts()) : $loop->the_post();
$src = wp_get_attachment_image_src( get_post_thumbnail_id($post->ID), 'tour_grid');
$terms = wp_get_post_terms($post->ID, 'offers', array( 'fields' => 'all' ));
$post_acf = get_fields($post->ID );
$term_list = wp_get_post_terms($post->ID, 'activity', array('fields' => 'all'));
$terms_activity = wp_get_post_terms($post->ID, 'activity_level', array('fields' => 'all' ));
$i=0.5;
//echo "<pre>";
//print_r(get_fields());
?>
<div class="col-lg-4 col-md-4 col-sm-4">
<div class="Featured-item">
<div class="Featured-item-img"><a href="<?php the_permalink(); ?>">
<?php the_post_thumbnail($size = 'post-thumbnail', $attr = '');?>
</a><?php if (isset($terms[0]->name)){ ?><div class="offer"><span><?php echo $terms[0]->name; ?>% Off</span></div><?php } ?>
</div>
<div class="Featured-item-diss">
<ul class="list-inline">
<li><a href="#" data-toggle="tooltip" title="<?php echo $post_acf['days_number']; ?> Days" ><i class="fa fa-sun-o"></i> <span><?php echo $post_acf['days_number']; ?> Days </span></a></li>
<li><a href="#" data-toggle="tooltip" title="<?php echo $post_acf['total_nights']; ?> Nights"><i class="fa fa-moon-o"></i> <span><?php echo $post_acf['total_nights']; ?> Nights</span> </a></li>
<li><a href="#" data-toggle="tooltip" title="<?php echo $term_list[0]->name; ?>">
<i class="<?php
if($term_list[0]->name=='Trek'){echo 'icon-hiking';}
if($term_list[0]->name=='Climb'){echo 'icon-mountain';}
if($term_list[0]->name=='Cycling'){echo 'icon-motorcycle';}
if($term_list[0]->name=='Discovery'){echo 'icon-europe';}
if($term_list[0]->name=='Family'){echo 'icon-family';}
if($term_list[0]->name=='Polar Cruise'){echo 'icon-cruise-ship';}
if($term_list[0]->name=='Wildlife'){echo 'icon-jungle';}
if($term_list[0]->name=='Winter'){echo 'icon-snow-ice';}
?>"></i> <span><?php echo $term_list[0]->name; ?></span>
</a></li>
<li><a href="" data-toggle="tooltip" title="<?php if($terms_activity[0]->name!=''){echo $terms_activity[0]->name;}else{echo '';} ?>">
<?php if($terms_activity[0]->name=='Challenging'){?>
<i class="icon-level6"></i>
<?php }if($terms_activity[0]->name=='Easy'){?>
<i class="icon-level2"></i>
<?php }if($terms_activity[0]->name=='Moderate'){?>
<i class="icon-level4"></i>
<?php }if($terms_activity[0]->name=='Tough'){?>
<i class="icon-level8"></i>
<?php }if($terms_activity[0]->name==''){?>
<i class="icon-level1"></i>
<?php }?>
<span> <?php if($terms_activity[0]->name!=''){echo $terms_activity[0]->name;}else{echo 'none';} ?></span>
</a></li>
</ul>
<div class="Featured-item-title">
<h4><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h4>
<?php the_field('sub_description');?>
</div>
<div class="price">
<h3>$<?php if (empty($terms[0]->name)){ echo $post_acf['regular_price']; } else{
echo $post_acf['regular_price']-($post_acf['regular_price']*($terms[0]->name))/100?><del>$<?php echo $post_acf['regular_price']; ?></del>
<?php } ?>
</h3>
</div>
<a href="<?php the_permalink(); ?>" class="btn btn-danger">BOOK NOW</a>
</div>
</div>
</div>
<?php //$j++;
endwhile; }
}
else{
echo '<span><i class="fa fa-exclamation" aria-hidden="true"></i> Oops! Holiday Type was not found!</span>';
} wp_reset_postdata();
?>
</div>
</div>
</div>
</section>
<?php get_footer();?>
pls anyone have idea where id did wrong?