I am trying to get the current post category slug from the custom post type
in the shortcode function but it is not working where I am mistaking? Here is my complete code. It is not getting the <?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 data-filter="<?php echo $slug; ?>"></div>
<?php
}
?>
<?php endwhile; endif; wp_reset_postdata(); ?>
CodePudding user response:
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']; ?>" "; } ?> col-md-4 col-sm-6 wow fadeInUp" data-wow-delay="0.3s">
<img src="<?php echo $work_main_image['url']; ?>" alt="">
</a>
<?php
endwhile;
wp_reset_postdata();
endif;
?>