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 Exchange
🌐
Wordpress
developer.wordpress.org › reference › functions › get_category_link
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
developer.wordpress.org › reference › functions › get_the_category
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.
Videos
April 24, 2022
1.13K
January 21, 2016
11.5K
August 25, 2015
8.82K
🌐
Stack Exchange
wordpress.stackexchange.com › questions › 245303 › print-current-post-category-during-wp-query
wp query - Print current post category during WP_Query - WordPress Development Stack Exchange

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 wordpress.stackexchange.com
🌐
WPExplorer
wpexplorer.com › tutorials › how to link to the current category in wordpress
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.
🌐
Stack Overflow
stackoverflow.com › questions › 22849124 › how-to-print-the-link-of-a-category-into-the-href-of-an-anchor-tag-in-wordpre
php - How to print the link of a category into the href="" of an anchor tag in Wordpress? - Stack Overflow

You need to get the category object and then use a foreach loop to build your list.

This should work for you:

<?php $categories = get_categories(); ?>
<nav>
  <?php foreach ($categories as $category):?>
    <a href="<?php echo get_category_link($category->term_id); ?>" class="nav-link" id="<?php echo $category->name;?>"><?php echo $category->name;?></a>
  <?php endforeach; ?>
</nav>
Answer from Hiram Hibbard on stackoverflow.com
🌐
Stack Overflow
stackoverflow.com › questions › 20039661 › get-current-category-link
php - Get current category link - Stack Overflow

get_* functions are return functions. They don't actually print anything. Given your code example, all you should need is an echo statement:

<?php 
global $post;
$category = reset(get_the_category($post->ID));
$category_id = $category->cat_ID;
?>

<a class="button" href="<?php echo get_category_link( $category_id ); ?>">&larr; Back to Portfolio</a>

ALTERNATIVE: The best way of doing this would be to keep everything in your loop for reuse in single or archive views, combined with the use of wp_get_post_categories. This is untested, but it should get you started with a general-use method of listing categories associated with a given post or set of posts:

<?php
if(have_posts()) : while(have_posts()) : the_post();
    $cats = wp_get_post_categories($post->ID);
    if($cats) : foreach($cats as $cat) : $category = get_category($cat);
    ?>
    <a class="button" href="<?php echo get_category_link($category->cat_ID); ?>">&larr; <?php echo $category->name ?></a>
    <?php
    endforeach;endif;
endwhile;endif;
?>
Answer from maiorano84 on stackoverflow.com
🌐
WisdmLabs
wisdmlabs.com › home › wordpress basics › how to create a link to current category in wordpress
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]
🌐
Stack Exchange
wordpress.stackexchange.com › questions › 131749 › display-current-category-title-on-category-page
php - Display current category title on category page - WordPress Development Stack Exchange

On a category page, you can use the function single_cat_title(), or the more generic single_term_title(). These functions pull from the global $wp_query object, via get_queried_object().

Answer from Milo on wordpress.stackexchange.com
Find elsewhere
🌐
GeneratePress
generatepress.com › forums › topic › how-to-generate-category-links-of-current-post
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 ); } ?>
🌐
Stack Exchange
wordpress.stackexchange.com › questions › 243856 › how-to-get-current-category
php - How to get current category - WordPress Development Stack Exchange

You can use get_queried_object(), which will return category object.

See documentation:

https://codex.wordpress.org/Function_Reference/get_queried_object

Answer from Aniruddha Gawade on wordpress.stackexchange.com
🌐
Stack Exchange
wordpress.stackexchange.com › questions › 274018 › get-category-url-for-current-post
functions - Get category URL for current post - WordPress Development Stack Exchange

Pass the category id into get_category_link():

<?php
$category = get_the_category();
$link = get_category_link( $category[0]->term_id );
?>

Update Outputting in template:

<?php
$category = get_the_category();
$first_category = $category[0];
echo sprintf( '<a href="%s">%s</a>', get_category_link( $first_category ), $first_category->name );
?>
Answer from Jacob Peattie on wordpress.stackexchange.com
🌐
Stack Exchange
wordpress.stackexchange.com › questions › 133867 › how-to-display-a-list-of-categories
How to display a list of categories - WordPress Development Stack Exchange

I will show you how to display a list of categories in WordPress and also mark the active category, see code below:

<?php
// Get the current queried object
$term    = get_queried_object();
$term_id = ( isset( $term->term_id ) ) ? (int) $term->term_id : 0;

$categories = get_categories( array(
    'taxonomy'   => 'category', // Taxonomy to retrieve terms for. We want 'category'. Note that this parameter is default to 'category', so you can omit it
    'orderby'    => 'name',
    'parent'     => 0,
    'hide_empty' => 0, // change to 1 to hide categores not having a single post
) );
?>

<ul>
    <?php
    foreach ( $categories as $category ) 
    {
        $cat_ID        = (int) $category->term_id;
        $category_name = $category->name;

        // When viewing a particular category, give it an [active] class
        $cat_class = ( $cat_ID == $term_id ) ? 'active' : 'not-active';

        // I don't like showing the [uncategoirzed] category
        if ( strtolower( $category_name ) != 'uncategorized' )
        {
            printf( '%3$s',
                esc_attr( $cat_class ),
                esc_url( get_category_link( $category->term_id ) ),
                esc_html( $category->name )
            );
        }
    }
    ?>
</ul>

Notes about the code above:

get_queried_object() retrieve the currently-queried object. For example:

  • if you're on a single post, it will return the post object
  • if you're on a page, it will return the page object
  • if you're on an archive page, it will return the post type object
  • if you're on a category archive, it will return the category object
  • if you're on an author archive, it will return the author object
  • etc.

But there are some implications when using get_queried_object(), you should not expect it to return a post type object even when is_post_type_archive() is true. Check it out for more info.

Also, note that get_queried_object() is a wrapper for $wp_query->get_queried_object(), so it returns a WP object data type.

get_categories()

get_categories() retrieve list of category objects. Currently accepts only one parameter - $args. The $args parameter specifies a list of arguments that should be used to retrieve categories. See get_terms() for additional options.

However, to get the category for a particular posts here's a simple function I wrote: How to get list of categories for a post

Answer from John Zenith on wordpress.stackexchange.com
🌐
Stack Overflow
stackoverflow.com › questions › 14816552 › wordpress-get-category-link
php - Wordpress get category link - Stack Overflow

Sounds like you may want get_category_link - something like:

$categories = get_categories();
foreach ($categories as $cat) {
    $category_link = get_category_link($cat->cat_ID);
    echo '<a href="' . esc_url($category_link) . '" title="' . esc_attr($cat->name) . '">' . esc_html($cat->name) . '</a>';
}

should print out the links to the categories for you.

Answer from anotherthink on stackoverflow.com
🌐
Stack Exchange
wordpress.stackexchange.com › questions › 108413 › direct-link-to-category
categories - Direct link to category? - WordPress Development Stack Exchange

There is a function called get_category_link() which might be helpful for you. This will be able to generate an appropriate link without having to hard-code it, except for the category name or ID.

Examples from the Wordpress Codex:

<?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 this category -->
<a href="<?php echo esc_url( $category_link ); ?>" title="Category Name">Category Name</a>

http://codex.wordpress.org/Function_Reference/get_category_link

Answer from Ben Cole on wordpress.stackexchange.com
🌐
Stack Exchange
wordpress.stackexchange.com › questions › 219954 › how-do-i-get-the-category-url-from-get-the-category
categories - How do I get the category URL from get_the_category? - WordPress Development Stack Exchange

Use:

get_category_link( $category_id );

See:

https://codex.wordpress.org/Function_Reference/get_category_link

In your specific case:

<?php
global $post;
$categories = get_the_category();

    foreach ($categories as $category) :

       $exclude = get_the_ID();
       $posts = get_posts('posts_per_page=4&category='. $category->term_id);

        foreach($posts as $post) :
         if( $exclude != get_the_ID() ) { ?>

                <a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>" class="post c-1"> Link to actual post</a>

    <?php } endforeach; ?>

<a href="<?php echo esc_url( get_category_link( $category->term_id ) ); ?>" title="View all" class="btn border"><i class="i-right-double-arrow"></i> View all <?php echo $category->name; ?></a>
<?php  endforeach; wp_reset_postdata(); ?>
Answer from Adam on wordpress.stackexchange.com
🌐
CodexWorld
codexworld.com › home › how to guides › how to get post category name and url in wordpress
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
codex.wordpress.org › Linking_Posts_Pages_and_Categories
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
developer.wordpress.org › reference › functions › get_categories
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
wpmudev.com › home › miscellaneous › how to get a wordpress category name without the link
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.
🌐
Stack Exchange
wordpress.stackexchange.com › questions › 59476 › get-current-category-id-php
get current category ID php - WordPress Development Stack Exchange

you can use get_queried_object()

$category = get_queried_object();
echo $category->term_id;
Answer from Milo on wordpress.stackexchange.com