Forums

get_category_link function returns current URL (6 posts)

  1. kmalone
    Member
    Posted 1 year ago #

    I'm having a problem with the get_category_link function. It only seems to return the current URL instead of the category URL. I think I've using it correctly, please see below for how I'm using the code.

    $args=array(
      'orderby' => 'name',
      'taxonomy' => 'custom-cat',
      'order' => 'ASC',
      'pad_counts' => true
      );
    
    $categories=get_categories($args);
    
    foreach($categories as $category) { 
    
    	$categorylink = (int) $categorylink;
    	echo $category->description . '<p><a href="' . get_category_link( $category->term_id ) . '" . ' . '>' . $category->name.'</a> </p> ';
    	echo  ( $category->term_id );
    
    }
  2. alchymyth
    The Sweeper
    Posted 1 year ago #

  3. loulantos
    Member
    Posted 11 months ago #

    i'm having this same problem, and arrived at this topic, but i don't understand why the above poster has suggested a get_term_link, and how it's meant to give me the relevant category link(s). Could someone please explain? It would be much appreciated.

  4. alchymyth
    The Sweeper
    Posted 11 months ago #

    @loulantos
    the original poster is working with a custom taxonomy ('taxonomy' => 'custom-cat') and therefore, get_category_link() is not the appropriate function to use.

    can you describe your problem in more detail - assuming that you are not using the same custom taxonomy as @kmalone ;-)

  5. urbanty
    Member
    Posted 5 months ago #

    Hi,

    I'm also having the problem that I'm always getting the current link instead of the link to a specific category.

    My extremely simple code looks like this:
    <a href="<?php get_category_link(1); ?>">Link &rarr;</a>

    With '1' being the ID of the category.
    Shouldn't this work?

    Many thanks in advance!

  6. alchymyth
    The Sweeper
    Posted 5 months ago #

    @urbanty
    you need to echo the 'get_category_link(1)';
    example:

    <a href="<?php echo get_category_link(1); ?>">Link &rarr;</a>

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

Topic Closed

This topic has been closed to new replies.

About this Topic