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

This is my custom function:

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) is allways using Plain url the default wordpress permalink option even if Post name is selected in my permalink settings.

so the url in browser is example.com/post_type=post&p=ID but I want to get the post name when I use %post% in the field I created.

When I use get_permalink or get_the_permalink I get blank wordpress pages. Is there anything else that I can try?

Thankyou.

Use the_permalink() function in loop whenever you want to use link and use /%postname%/ instead of %post% in permalink setting.