You are using the get_the_terms()
but this function is used to get the custom taxonomies.
Use the function get_the_category();
inside the WordPress loop and pass the get_the_ID()
function which will get the current post ID in the loop.
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="">
</a>
<?php
endwhile;
wp_reset_postdata();
endif;
?>
Cheers :)
Answer from Syed Fakhar Abbas on Stack ExchangeWordpress
get_category_link() – Function | Developer.WordPress.org
You must log in to vote on the ... log in to vote on the helpfulness of this note ... <?php // Get the ID of a given category $category_id = get_cat_ID( 'Category Name' ); // Get the URL of this category $category_link = get_category_link( $category_id ); ?> <!-- Print a link to ...
Wordpress
get_the_category() – Function | Developer.WordPress.org
You must log in to vote on the helpfulness of this noteVote results for this note: 9You must log in to vote on the helpfulness of this note · Show All Categories as Links This outputs all the categories assigned to the post as links. Must be used inside the loop.
WPExplorer
How to Link to the Current Category in WordPress
September 26, 2023 - This tutorial will show you how to link to the current category for the post you are viewing in WordPress using a code snippet.
WisdmLabs
How To Create A Link To Current Category In WordPress
April 7, 2014 - <a href=”<?php echo $category_link ?>” title=”<?php echo $category_name ?>” > <?php echo $category_name ?> </a>[/pre]
GeneratePress
How to Generate Category Links of Current Post – GeneratePress
<?php $categories = get_the_category(); foreach ( $categories as $key=>$category ) { echo sprintf( '%s', get_category_link( $category ), $category->name ); } ?>
CodexWorld
How to Get Post Category Name and URL in WordPress - CodexWorld
November 20, 2015 - WordPress Get Post Category - Display category of the post in WordPress. Get the current post category name, slug, or URL in WordPress.
Wordpress
Linking Posts Pages and Categories « WordPress Codex
When doing so, you may safely omit ... and link to the target with a full path: ... The leading slash means "At the very top of this domain is a directory named wordpress, and inside this directory is a file named index.php". ... The lack of a leading slash means "Inside the current directory ...
Wordpress
get_categories() – Function | Developer.WordPress.org
List Categories and Descriptions This example will list, in alphabetic order, all categories presented as links to the corresponding category archive. Each category description is listed after the category link. <?php $categories = get_categories( array( 'orderby' => 'name', 'order' => 'ASC' ...
WPMU DEV Blog
How to Get a WordPress Category Name Without the Link - WPMU DEV
March 11, 2022 - Have you ever needed to display the name of your current category without a link? In this article, we'll show you how to do that by adding a few lines of code.