【问题标题】:Change the post URL based on author ID根据作者 ID 更改帖子 URL
【发布时间】:2021-09-17 13:43:52
【问题描述】:

我想实现自定义帖子网址。

目前帖子的网址是这样的:http://example.org/post-url/

我想做类似 http://example.org/_blog/_blog_post/post-url/ 之类的事情 我想在帖子网址之前添加 /_blog/_blog_post/

如果作者的ID是7.自定义url会在博文url生效 如果不是,则帖子网址将保持为:http://example.org/post-url/

这是我在functions.php中的当前代码

$args = get_user_by( 'id', 7 ); 
$wp_posts = get_posts($args);

if (count($wp_posts)) {
    global $wp_rewrite; 
    $wp_rewrite->set_permalink_structure( $wp_rewrite->root . '/_blog_/internship_blog/%postname%/');
}
else {
    global $wp_rewrite; 
    $wp_rewrite->set_permalink_structure( $wp_rewrite->root . '/%postname%/');
    }

【问题讨论】:

    标签: php wordpress function


    【解决方案1】:

    您正在寻找Rewrite endpoints API, 我使用此 API 在我的帖子网址后添加 /download/

    【讨论】:

      猜你喜欢
      • 2013-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多