categories - Get category URL knowing it's id

I have id of WP category on external resource.I know that if I have id of post I can create url like?p={post_id}But wh

I have id of WP category on external resource. I know that if I have id of post I can create url like

/?p={post_id}

But what if I know id of category? How can I generate link to it? Category permalinks look like

/{category_slug}/

and I need to use something like

/?cat_id={category_id}/

I have id of WP category on external resource. I know that if I have id of post I can create url like

http://example/?p={post_id}

But what if I know id of category? How can I generate link to it? Category permalinks look like

http://example/category/{category_slug}/

and I need to use something like

http://example/category/?cat_id={category_id}/

Share Improve this question asked Dec 27, 2017 at 8:07 moonvadermoonvader 3325 silver badges17 bronze badges 2
  • Set Permalinks to Plain and visit a category to see for yourself. – Jacob Peattie Commented Dec 27, 2017 at 9:42
  • Custom taxonomy: you can do ?taxonomy_key=a-term-slug e.g. ?sport_category=some-ball-game , I had no luck of finding a way with just term_id ... – jave.web Commented May 3, 2021 at 0:01
Add a comment  | 

3 Answers 3

Reset to default 3

If you have category ID you can create link to category like below :

<a href="/index.php?cat=7">Category Title</a>

For more details read from this link :

https://codex.wordpress/Linking_Posts_Pages_and_Categories

Thanks!

use get_term_link:

print get_term_link( $category_id, $taxonomy );

If you have the category id then you can easily get the category URL using the below code.

get_category_link( $category_id );

Example:

<a href="<?php echo esc_url( get_category_link( $category_id) ); ?>"  class="view_more_button">View More</a>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744737312a4590827.html

相关推荐

  • categories - Get category URL knowing it&#39;s id

    I have id of WP category on external resource.I know that if I have id of post I can create url like?p={post_id}But wh

    3天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信