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

enter image description here

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
  • 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 Dec 22 '15 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 Dec 23 '15 at 11:02

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.