很难得到我的分类法。php运行良好。
我使用分类法。php来列出我在特定类别中的所有帖子,但它显示了我在所有类别中的所有帖子。
这是我的代码:
<ul class="scenes cf">
<?php
$args1 = array(
\'post_type\'=>\'artistes\',
\'orderby\' => \'menu_order\',
\'order\' => \'ASC\',
\'meta_query\' => array(
array(
\'key\' => \'date_de_lartiste\',
\'value\' => \'\',
\'compare\' => \'LIKE\'
),
array(
\'key\' => \'heure_de_lartiste\',
\'value\' => \'\',
\'compare\' => \'LIKE\'
)
)
);
add_filter(\'posts_orderby\',\'orderbyreplace\');
$loop = new WP_Query( $args1 );
remove_filter(\'posts_orderby\',\'orderbyreplace\');
?>
<?php $todaysDate = date(\'Y/m/d\'); ?>
<?php if ($loop->have_posts() ) { while ( $loop->have_posts() ) { $loop->the_post(); ?>
<?php
$date = get_field(\'date_de_lartiste\');
$newDate = date("d/m/Y", strtotime($date));
?>
<li>
<div class="info">
<?php the_post_thumbnail( \'artists_list\' )?>
<p><?php the_title(); ?></p>
<p class="music_style"><?php echo $newDate ?> - <?php the_field(\'heure_de_lartiste\'); ?></p>
</div>
<a href="<?php the_permalink(); ?>" class="read_more"><?php _e(\'Read More\'); ?></a>
</li>
<?php
}
} else {
?>
<li class="cf">
<p>No posts</p>
</li>
<?php
}
/* Restore original Post Data */
wp_reset_postdata();
?>
</ul>
有人能帮我弄明白吗?如何仅显示当前分类中的帖子?非常感谢,
Jhon公司
EDIT:
我知道这是最好的方法,但我只是用以下代码修复了它:$category = get_query_var( \'term\' );
在我的$args中,我添加了:\'tax_query\' => array(
array(
\'taxonomy\' => \'scenes\',
\'field\' => \'slug\',
\'terms\' => "$category"
)
),