$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>retrieve permalinks of posts inside custom post type by using post ID|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

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

matteradmin8PV0评论

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.

Post a comment

comment list (0)

  1. No comments so far