Custom search filter causes menu and query_posts problems

Use is_main_query() to modify only the main query so menu will stay not affected. Try This: add_action( ‘pre_get_posts’, ‘fteh_pre_get_posts’ ); function fteh_pre_get_posts( $query ){ if( !is_admin() && $query->is_main_query() && isset( $query->query_vars[‘type’] ) ) $types = explode( ‘,’, $query->query_vars[‘type’] ); $query->set( ‘post_type’, $types ); return $query; }

Include and Exclude Taxonomies From Archives & Feeds Using ‘pre_get_posts’

I’ll take another shot. The following should modify the main query, such that it will include in its loop any posts that belong to no term of the Edition custom taxonomy. add_filter(‘pre_get_posts’,’better_editions_archive’); function better_editions_archive( $query ) { if ( $query->is_tax( ‘edition’ ) && $query->is_main_query() ) { $terms = get_terms( ‘edition’, array( ‘fields’ => ‘ids’ ) … Read more

Custom Table Column Sortable by Taxonomy Query

To achieve adding a custom sortable column to the WP_List_Table of your post type within the WordPress administration back-end dashboard, you will need to do the following: Replace all occurrences of YOUR-POST-TYPE-NAME with your actual post type name. Replace all occurrences of YOUR-TAXONOMY-NAME with your actual taxonomy name. Replace all occurrences of YOUR COLUMN NAME … Read more

sort child pages on admin

As I couldn’t find any filter to override the WP_Posts_List_Table class, I propose a quite hacky solution by doing this: Query only parents in pre_get_posts; Query their children on wp and change $wp_query->posts accordingly. This might need some more work as I’m probably breaking pagination numbers or so. // Use a query variable to control … Read more

Using pre_get_posts to rewrite search query to display posts from multiple taxonomies

It does’t work because you can’t use set to change all query vars. Simplest way to do the trick is set ‘s’ to an empty string: add_action( ‘pre_get_posts’, function( $query ) { if ( ! is_admin() && $query->is_main_query() && $query->is_search() ) { $taxquery = array( … ); $query->set( ‘tax_query’, $taxquery ); $query->set(‘s’, ” ); } … Read more

Prevent pre_get_posts filter on specific post type

Improve your conditional to include a check for post type being queried. It can be done via WP_Query::get method So, where you have if ( !is_admin() ){ $query->set( ‘meta_key’, ‘_ct_selectbox_52f65ae267764’ ); $query->set( ‘meta_value’, $city ); return; } replace with if ( ! is_admin() && in_array ( $query->get(‘post_type’), array(‘event’,’venue’) ) ) { $query->set( ‘meta_key’, ‘_ct_selectbox_52f65ae267764’ ); … Read more