Answer the question
In order to leave comments, you need to log in
CNC WordPress conflicts with custom, how to fix?
The problem is, there is a page of Biographies with its own template, it searches for a person from the database using the get ID parameter and everything works well, but the site.ru/biography?id=42 link looks not very good, I added a rule to the .htaccess file for mod_rewrite
...
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^biography/([^/\.]+)/?$ biography/?id=$1 [L]
...
Answer the question
In order to leave comments, you need to log in
Firstly, you have a redirect with a get parameter, but it is not transmitted in this way at all, for a redirect with a get, a two-level construction is used. Where you can exclude in addition everything that you need.
Perhaps crooked, but I was able to decide, the article helped. You
need to reassign Rewrite:
add_filter( 'rewrite_rules_array','my_insert_rewrite_rules' );
add_filter( 'query_vars','my_insert_query_vars' );
add_action( 'wp_loaded','my_flush_rules' );
// Сбиваем правила flush_rules(), если наших еще нет в списке (операция ресурсоемкая, поэтому не стоит ее делать каждый раз)
function my_flush_rules(){
$rules = get_option( 'rewrite_rules' );
// достаточно проверить, есть ли в списке хотя бы одно из наших правил
if ( ! isset( $rules['biography/([^/]*)/?$'] ) ) {
global $wp_rewrite;
$wp_rewrite->flush_rules();
}
}
// Добавляем наши правила
function my_insert_rewrite_rules( $rules )
{
$newrules = array();
$newrules['biography/([^/]*)/?$'] = 'index.php?pagename=biography';
return $newrules + $rules; // так оно добавляет наши правила к уже существующим, а еще мы можем тупо убрать все и вернуть только свой список, сделав return $newrules;
}
// Добавляем переменную id, чтобы WP воспринимал ее
function my_insert_query_vars( $vars )
{
array_push($vars, 'id');
return $vars;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question