Wordpress CNC get parameter
There is a page stranicza-profilya, I output the get parameter on it site.com/stranicza-profilya/?id=field845604 Please tell me how I can style the url in the form of site.com/stranicza-profilya/field845604/
I tried a lot of options in function.php
function rewrite_rules() {
// Теги
add_rewrite_tag( '%id%', '([^&]+)', 'id=' );
// Правило перезаписи
add_rewrite_rule( '^stranicza-profilya/([^/]*)/?', 'index.php?page_id=13&id=$matches[1]', 'top' );
// Скажем WP, что есть новые параметры запроса
add_filter( 'query_vars', function( $vars ) {
$vars[] = 'id';
return $vars;
} );
}
add_action( 'init', 'rewrite_rules' );
Unfortunately, it doesn't work even when I resave the CNC. I don't want to enter it directly in htaccess, since wp automatically creates it and there is a chance that it may be lost in the future his. Please help me
0
Author: Алексей Федосов, 2020-12-07
1 answers
I checked your code, it works.
In order for the rule to start working, you need to update (reset) the rules in the database. To do this, call the flush_rules () function. Or just go to Settings -> Permalinks, flush_rules () will automatically work there.
1
Author: KodimWeb, 2020-12-07 11:42:32