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
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.