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 );
}
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.
@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 ;-)
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 →</a>
With '1' being the ID of the category.
Shouldn't this work?
Many thanks in advance!
@urbanty
you need to echo the 'get_category_link(1)';
example:
<a href="<?php echo get_category_link(1); ?>">Link →</a>
http://codex.wordpress.org/Function_Reference/get_category_link#Examples