我通过一个术语过滤器(第一个分类法)显示post,它工作得很好。
我添加了另一个术语列表过滤器(第二种分类法)。
我想在每个分类法中选择一个术语后显示帖子。
谢谢你的帮助。
/* First taxonomy\'s template. It works like a charm. */
$query = new \\WP_Query(array(
\'post_type\' => \'postwork\',
\'tax_query\' => array(
array(
\'taxonomy\' => \'workfilter\',
\'field\' => \'term_id\',
\'terms\' => get_queried_object_id(),
)
)
));
/* Second taxonomy\'s template. It doesn\'t work I don\'t know how to recover the first term value */
$query = new \\WP_Query(array(
\'post_type\' => \'postwork\',
\'tax_query\' => array(
\'relation\' => \'AND\',
array(
\'taxonomy\' => \'workfilter\', /* first taxonomy */
\'field\' => \'term_id\',
\'terms\' => \'\', /* Want to get the term */
),
array(
\'taxonomy\' => \'workfiltercondition\', /* second taxonomy */
\'field\' => \'term_id\',
\'terms\' => get_queried_object_id(),
)
)
));
/* Loop to display posts */
if ( $query->have_posts() ): ?>
<div class="container-fluid">
<div class="works-list">
<?php while ( $query->have_posts() ) : $query->the_post(); ?>
<div class="works-item">
<a href="<?php echo get_permalink(); ?>">
<img src="<?php echo get_the_post_thumbnail_url(); ?>" alt="" />
<div class="d-flex justify-content-between works-info">
<div>
<h2><?php echo get_the_title(); ?></h2>
<p><?php echo the_field(\'work_place\'); ?></p>
</div>
</div>
</a>
</div>
<?php endwhile; ?>
</div>
</div>
<?php endif;
/* jQuery Script to works with Ajax */
jQuery(function(){
var mainContent = jQuery(\'.container-fluid\');
var catLinks = jQuery(\'ul.categories-filters li a\');
catLinks.on(\'click\', function(e){
e.preventDefault();
el = jQuery(this);
var value = el.attr("href");
mainContent.animate({opacity:"0.5"});
mainContent.load(value + " .works-list", function(){
mainContent.animate({opacity:"1"});
});
jQuery( "li" ).removeClass( "current-cat" );
jQuery(this).closest(\'li\').addClass("current-cat");
});
});