我担心我将不得不编写一堆代码来获得我需要的东西,这很好,但我想在开始这段旅程之前检查一下是否有任何内置的东西。
我正在开发一个插件,我需要获取给定插件的相对路径permalink_structure
. 当前,permalink结构选项返回/%postname%/%post_id%/
. 我有帖子(页面)id,例如100。
根据permalink的设置,我知道完整的相对路径应该是/iamapost/100
. 然而,似乎我能做的最好的事情是:
get_permalink($post_id) === "https://example.com/iamapost/";
parse_url(get_permalink($post_id), PHP_URL_PATH) === "/iamapost/";
get_post_permalink($post_id) === "https://example.com/?post_type=page&p=100";
get_site_uri === "https://example.com";
鉴于:get_option(\'permalink_structure\') === "/%postname%/%post_id%/";
相对路径是否可以从此permalink设置页上设置的permalink结构或任何permalink结构中获取-无论是什么。。。Please, please do not assume this is a duplicate, because I really have searched and no question and answer is specific to reacting to whatever the permalink structure is at the time. If such an answer exists, then cool.