您正在设置$terms_portfolio
太早了。您正在使用get_the_terms( get_the_ID(), \'portfolio_categories\')
, 但是get_the_ID()
不会是循环中的当前投资组合,因为$portfolio_query->the_post()
尚未运行。
更改此位:
<?php $portfolio_query = new WP_Query(array(
\'post_type\' => \'portfolios\',
\'order\' => \'DESC\',
));
$terms_portfolio = get_the_terms( get_the_ID(), \'portfolio_categories\');
?>
<?php if($portfolio_query->have_posts()) : while($portfolio_query->have_posts()) : $portfolio_query->the_post(); ?>
<div class="col-md-4" data-tag="<?php echo $terms_portfolio[0]->slug; ?>">
收件人:
<?php
$portfolio_query = new WP_Query(array(
\'post_type\' => \'portfolios\',
\'order\' => \'DESC\',
));
if($portfolio_query->have_posts()) :
while($portfolio_query->have_posts()) : $portfolio_query->the_post();
$terms_portfolio = get_the_terms( get_the_ID(), \'portfolio_categories\');
?>
<div class="col-md-4" data-tag="<?php echo $terms_portfolio[0]->slug; ?>">