我正在嘗試從簡碼函式中的自定義帖子型別中獲取當前的帖子類別 slug,但它在我弄錯的地方不起作用?這是我的完整代碼。它沒有得到<?php echo $slug; ?>
<?php
$mi_args = array(
'post_status' => 'publish',
'posts_per_page' => '99999',
'post_type' => 'blog'
);
$mi_query = new WP_Query($mi_args);
if($mi_query->have_posts()):
while ($mi_query->have_posts()): $mi_query->the_post();
$portfolio_url = get_post_meta( get_the_ID(), 'portfolio_url_portfolio-url', true );
$hover_color = get_post_meta( get_the_ID(), 'hove_color_hover-color', true );
// Getting the category slug
$categories = get_the_category(get_the_ID());
foreach ($categories as $category){
$slug = $category->slug;
?>
<?php echo $slug; ?>
<div class="grid-item" data-filter="<?php echo $slug; ?>"></div>
<?php
}
?>
<?php endwhile; endif; wp_reset_postdata(); ?>
uj5u.com熱心網友回復:
get_the_category(get_the_ID());
<?php
$args = array(
'post_type' => 'work',
'posts_per_page' => '9'
);
$work_loop = new WP_Query( $args );
if ( $work_loop->have_posts() ) :
while ( $work_loop->have_posts() ) : $work_loop->the_post();
// Set variables
$cat_ids = get_the_ID();
$cat_names_array = get_the_category($ids);
$work_category = get_the_category( get_the_ID() );
$work_title = get_field( 'work_title' );
$work_main_image = get_field( 'work_main_image' );
$work_link = get_field( 'work_title' );
$work_about = get_field( 'work_about' );
// $work_category = get_the_terms( the_post()->ID, 'taxonomy' );
// Output
?>
<a href="<?php echo $work_main_image['url']; ?>" class="single_item link <?php foreach ( $work_category as $key => $value) { echo $value->category_nicename . " "; } ?> col-md-4 col-sm-6 wow fadeInUp" data-wow-delay="0.3s">
<img src="<?php echo $work_main_image['url']; ?>" alt="在 wordpress 自定義帖子型別查詢中獲取當前帖子類別 slug">
</a>
<?php
endwhile;
wp_reset_postdata();
endif;
?>
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/454719.html
上一篇:.HTACCESS添加到slug
