繁体   English   中英

即使在永久链接设置中选择了帖子名称,get_post_permalink也会使用普通格式

[英]get_post_permalink uses Plain even if the Post name is selected in permalink settings

这是我的自定义函数:

add_filter('post_link', 'get_custom_permalink', 10, 4);
function get_custom_permalink($permalink, $post, $leavename = false) {
$options = get_option('my-options');
$custom_field = $options['my_field'];
//$permalink = get_option('permalink_structure');
$url = $options['agg_permalink'];
$url = str_replace("%post%", get_post_permalink($post), $url);
$url = str_replace("%site%", get_site_url(), $url);
$url = str_replace("%home%", get_home_url(), $url);
  if (!empty($url) ) {
    return $url;
    } else {
      return $permalink;
    }
}

get_post_permalink($post)始终使用普通url作为默认的wordpress永久链接选项,即使在我的永久链接设置中选择了发件人姓名也是如此。

因此浏览器中的网址是example.com/post_type=post&p=ID但是当我在创建的字段中使用%post%时,我想获取帖子名称。

当我使用get_permalinkget_the_permalink我会得到空白的wordpress页面。 还有什么我可以尝试的吗?

谢谢。

每当您要使用链接并在永久链接设置中使用/%postname%/而不是%post%时,请循环使用the_permalink()函数。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM