Php 具有id和slug的永久链接(但id路由)

Php 具有id和slug的永久链接(但id路由),php,mysql,wordpress,custom-wordpress-pages,Php,Mysql,Wordpress,Custom Wordpress Pages,我的舞台: 使用PHP7.2 WordPress 5.2.4 我希望我的永久链接可以通过post/id和title slug访问,如: example-page.com/post_id/ 及 我想要实现的是: URL应该是show title slug,但只能以/10/的形式按ID查询页面。这是title slug 我必须在functions.php或WordPress permalinks设置中输入什么?在您的情况下,应该是: /%post\u id%/%postname%/在您的情况下,它

我的舞台: 使用PHP7.2 WordPress 5.2.4

我希望我的永久链接可以通过post/id和title slug访问,如:

example-page.com/post_id/

我想要实现的是: URL应该是show title slug,但只能以/10/的形式按ID查询页面。这是title slug


我必须在functions.php或WordPress permalinks设置中输入什么?

在您的情况下,应该是:


/%post\u id%/%postname%/

在您的情况下,它应该是:


/%post\u id%/%postname%/

太好了,谢谢!如何将meta_字段名添加到永久链接设置?所以我在post的metafield中有id为的metafield。我想用它来代替%post_id%你是如何创建元字段的?您是否尝试只输入%meta_字段_id%?我对cmb2元盒使用了这种语法。我在我的functions.php中使用了这个片段在post中创建元字段:add_action('save_post','add_discount_meta');函数add_discount_meta($post_id){{{global$post;update_post_meta($post_id,'metafieldname',$post_id);}}}嗯,这行吗?函数custom_meta_permalink($link,$post){$post_meta=get_post_meta($post->ID,'metafieldname',true);if(empty($post_meta)|!is_string($post_meta))$post_meta='''link=str_replace('!!自定义_字段占位符!!,$post_meta,$link);return$link;}add过滤器('post_link,'link','custom meta_permalink,';并通过/%postname%/调用链接!!自定义\字段\占位符!!/(未测试!)尝试此pls:D函数custom_meta_permalink($link,$post){$post_meta=get_post_meta($post->ID,'metafieldname',false);if(empty($post_meta)| | is_string($post_meta))$post_meta='';link=str replace(“!!custom_field占位符!!,$post_meta,$link,$link);return$link;}add过滤器('post_link'、'custom_meta_permalink',10,2);太好了,thx!我如何将meta_字段名称添加到permalinks设置中?因此我在post的metafield中使用了id为的metafield。我想使用它而不是%post_id%如何创建metafields?您是否尝试只输入%meta_field_id%?我对cmb2 Metaboxes使用了此语法我在functions.php中使用此片段在post:add_actio中创建metafieldn('save_post','add_discount_meta');函数add_discount_meta($post_id){{global$post;update_post_meta($post_id,'metafieldname',$post_id);}}嗯,这行吗?函数custom_meta permalink($link,$post){$post_meta=get_post_meta($post->id,'metafieldname',true);if(空($post_meta)| |!is_string($post_meta))$post_meta='';$link=str_replace(“!!自定义_字段_占位符!!”,$post_meta,$link);return$link;}添加过滤器('post_link','custom_meta u permalink',10,2);并通过/%postname%/!!自定义_字段_占位符!!/(未测试!)请尝试以下方法:D函数custom_meta_permalink($link,$post){$post_meta=get_post_meta($post->ID,'metafieldname',false);if(empty($post_meta)|!is_string($post_meta))$post_meta='';$link=str replace('!!custom_field占位符!!,$post_meta link,$link);return$link;}add过滤器('post_link link,'link,'post_link,'link,';
example-page.com/post_id/post_title