redirect_canonical hook redirects, though unintended
-
I have following
pre_get_posts
setup:add_action('pre_get_posts', function($query) { if($query->is_main_query() && !is_admin()) { $lang = get_query_var('lang', 'en'); $meta_query[] = [ 'RELATION' => 'AND', [ 'key' => 'language', 'value' => $lang, 'compare' => '=' ] ]; $query->set('meta_query', $meta_query); } });
And it works, but redirect_canonical redirects to the post even when the main query has 0 posts, instead of delivering a 404 page. The function redirects to the post with the same “slug” (postname), which is wrong. How can I correct this?
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘redirect_canonical hook redirects, though unintended’ is closed to new replies.