retrieve permalinks of posts inside custom post type by using post ID

admin2025-06-02  0

I have these custom post types registered as shown in the image below -

In each of these custom post types, there are many posts. I have the function to retrieve the post IDs of each posts inside but I don't have a function to retrieve the permalinks.

I've used Pods Framework to get this done. How can I retrieve the permalinks on each posts using the post ID?

The end result should be something like -

echo home_url() / post_type / post_name

I have these custom post types registered as shown in the image below -

In each of these custom post types, there are many posts. I have the function to retrieve the post IDs of each posts inside but I don't have a function to retrieve the permalinks.

I've used Pods Framework to get this done. How can I retrieve the permalinks on each posts using the post ID?

The end result should be something like -

echo home_url() / post_type / post_name
Share Improve this question edited Aug 4, 2017 at 9:13 Johansson 15.4k11 gold badges44 silver badges80 bronze badges asked Dec 22, 2015 at 11:13 Siddharth ThevarilSiddharth Thevaril 6178 silver badges22 bronze badges 2
  • Where do you want this permalink to display and for what purpose? Do you want to show a "Recent Posts" or do you want to pull specific posts? I ask because I'm not sure if you want to pull all permalinks regardless of ID or if you want to be able to specify the ID? – amandathewebdev Commented Dec 22, 2015 at 16:17
  • @Antu Suppose the post type CLIENTS has posts such as post_1, post_2, post_3...each have postID as p1,p2,p3,p4...etc. I need to use p1 to get permalink of post_1, p2 to get permalink of post_2...etc – Siddharth Thevaril Commented Dec 23, 2015 at 11:02
Add a comment  | 

1 Answer 1

Reset to default 2

Maybe I'm missing something, but you seem to have missed one of the most ubiquitous functions in WordPress Core-- get_permalink(). The function accepts two optional parameters, the first of which is the post ID. So, to get the permalink via the post ID all you need is $perm = get_permalink($post_ID);. If you just need to echo the permalink you can use the_permalink($post_ID); instead.

As for "something like" echo home_url() / post_type / post_name, you don't really get to choose the permalink structure ad hoc like that. It won't work. WordPress Core won't know how to process the request. You will have to configure your permalinks to match that pattern then the functions above will generate them appropriately.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748823713a314022.html

最新回复(0)