Answer the question
In order to leave comments, you need to log in
After editing wp_query in pre_get_posts gives 404 page?
I simplified the code as much as possible, and after that, instead of the filtering page, it gives out the 404th:
add_action( 'pre_get_posts', 'action_function_name_11' );
function action_function_name_11( $query ) {
if ( isset($_GET['research_me']) && $query->is_main_query() ) {
$meta = array(
array(
'key' => 'test123',
'value' => 'text5',
'compare' => '='
)
);
$query->set('meta_query',$meta );
}
}
$query->set('meta_query',$meta );
Answer the question
In order to leave comments, you need to log in
pre_get_posts did not affect the query in any way, because such a topic, search results and wp_query construction took place in a shortcode
You are overwriting the parameters, but they must be added to the existing ones:
add_action( 'pre_get_posts', 'action_function_name_11' );
function action_function_name_11( $query ) {
if ( isset($_GET['research_me']) && $query->is_main_query() ) {
$meta = $query->get('meta_query');
$meta[] = array(
'key' => 'test123',
'value' => 'text5',
'compare' => '='
);
$query->set('meta_query', $meta);
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question