最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

plugins - Change custom rewrite rule when permalink is updatedchanged

programmeradmin1浏览0评论

I have a scenario where i need to make a rewrite rule dynamic so that when permalink is changed the re-write rule should get updated as well

function rewrite_rule() { 
    global $wp_rewrite;
    $post = get_post($result_id);
    $post_slug  = $post_id  ->post_name


    add_rewrite_rule('^'.$post_slug.'/([^/]*)/?','index.php?post_type=page&page_id=1234&term=$matches[1]','top');

    $wp_rewrite->flush_rules(true); 
} 

add_action('init', 'rewrite_rule' );

In this case

$post_slug

should be the permalink slug value from wordpress and everytime user changes the permalink value the rewrite should be updated with the value as well

发布评论

评论列表(0)

  1. 暂无评论