admin管理员组

文章数量:1426895

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

本文标签: pluginsChange custom rewrite rule when permalink is updatedchanged