Include different loop templates in search query

I would recommend using content-{posttype}.php method, where you only have HTML markup, template tags for posts or custom post types and leave loops outside of those files. See Twenty Eleven for more detailed example. After this change you can easily modify search.php and include specific content markup based on post type. if ( have_posts() ) … Read more

Can not switch the queried post in pre_get_posts hook

Huh. I double-checked. On my local server, this bit of code successfully changes the post: function test_redirect() { global $wp_query; $wp_query->set(‘page_id’, 5); } add_action(‘pre_get_posts’, ‘test_redirect’); You’re going to have to do a bit of debugging. On a dev server, var_dump the $wp_query variable a few key places to check that it has what you expect … Read more

How to Check if a Child Category is Being Queried

The function cat_is_ancestor_of takes two arguments (two category IDs). To check if category of ID 61 is ancestor of category with 54: cat_is_ancestor_of(54,61); I’m not sure if there is a better way of doing this, but you can get the current category’s ID with the get_queried_object() and then check this an ancestor of the category … Read more

Dynamically redirect page based on URL?

Assuming you stick with add_rewrite_rule(), if language and title where set as meta data on the /en/ post, then you can simplify the search down to a simple WP_Meta_Query() for /:lang/:title/ and pull the actually ID of the translated post there. Translations for /en/best-restaurants-in-tokyo: “/it/migliori-ristoranti-a-tokyo” => 4016 “/fr/meilleurs-restaurants-à-tokyo” => 4017