Ok I find a solution. I use posts_where
filter in pre_get_posts
. With this filter I can remove the term related WHERE
part from the default SQL query.
function custom_loops($query) {
if (is_tax( 'service_photo_location' )){
$query->set( 'posts_per_page', 10);
$query->set( 'post__in', $ids);
$query->set( 'orderby', 'title');
$query->set( 'order', 'ASC');
add_filter( 'posts_where', function ( $where ) {
$where = str_replace("AND ( wp_term_relationships.term_taxonomy_id IN (778) )", "", $where);
return $where;
}, 10, 2 );
}
remove_action( 'pre_get_posts', 'custom_loops' );
}
add_action('pre_get_posts', 'custom_loops');
Related Posts:
- Modify Taxonomy pages to exclude items in child taxonomies
- Removing taxonomy query by pre_get_posts
- Modify Taxonomy pages to exclude items in child taxonomies
- Sticky Posts exceed posts per page limit
- Theres a way to use $query->set(‘tax_query’ in pre_get_posts filter?
- Obliterate the main query and replace it
- Post injection – how to exclude the original post
- Adding meta_key via pre_get_posts causes navigation to disappear
- Sorting posts that has a meta value first then the rest of the posts
- pre_get_posts on a page
- How pre_get_posts filter by roles in WP Admin
- Weird problem with pre_get_posts and $query->is_page()
- SQL Statement generated by WP_Query not producing expected results
- Why is ‘pre_get_posts’ having no effect?
- Date Query to Pull Current and Future Posts
- pre_get_posts all posts and custom post type with certain tag
- Using Sessions to Filter Posts – bad thing?
- pre_get_posts and the blog page
- Archive by custom post type and custom date field
- pre_get_post filter returns results when there should not be
- Trying to exclude first 5 posts from the first page on the homepage
- Exclude a WordPress post from pre_get_posts if a field is null
- Why the ‘date_query’ is not working in ‘pre_get_posts’ hook?
- Only show certain post types in recent posts widget
- pre_get_posts for exclude category
- pre_get_posts: using tax_query only for certain post type
- pre_get_posts dont firing… Anybody knows whats the wrong with my code?
- Restrict Search Query To After Specific Date
- Include posts from feature category in pre_get_posts
- WP_Error not displaying errors
- Show all posts even if URL points to a single one
- How to achieve post_status__not_in?
- Ordering by meta_key
- Using a pre_get_posts filter to search for multiple strings on all meta values
- Using different parameters for different queries with pre get posts in functions.php
- how to restrict posts_request filter to the main query only
- Automatically applying a pre_get_posts filter for child categories only
- How to override a query and display specific page by ID?
- pre_get_posts variables
- Another query in pre_get_post cause memory issue
- pre_get_posts having no effect on my category archive
- pre_get_posts returns non property object when using posts__not_in
- Override tax_query with pre_get_posts to include other term_ids on a single category
- $query->is_main_query() is causing query’s tax_query to be ignored
- Menu disappears when meta_key changed [closed]
- pre_get_posts with multiple queries
- How to show the last and newest modified post in a custom category?
- Altering the main query using get_post_meta() in pre_get_posts
- Why query by specific date with variables doesn’t return same result that with harcoded integers?
- Sort WordPress Archive by multiple oderby arguments in pre_get_posts action
- Exclude post type with pre_get_posts?
- Exclude page by title for non admins
- problem with setting tax_query in pre_get_posts
- Add terms to a taxonomy archive from within the same taxonomy
- Tax query get first product with attribute value in pre_get_posts
- Problem ID to exclude specific posts from category
- Modify author archive query to combine two queries
- Change post order on archive to be displayed by most commented being ignored by theme
- Complex query using pre_get_posts
- Super confusing ‘pre_get_posts’ behavior with $query->set
- Having trouble with settings terms as array in pre_get_posts
- Override main query for page template
- Querying custom taxonomy on category-specific page is overwritten by function
- how to get content from other site and show it?
- Insert a variable in pre_get_posts
- Set a custom number of posts on the first page
- Why does this query not SELECT post IDs like a normal query would?
- Please ensure me that I’m not crazy using the pre_get_posts [closed]
- How to pass >= condition filter to my year custom tax_query
- What is the proper way to use pre_get_post?
- Querying posts globally based on custom taxonomy with its own taxonomymeta table
- pre_get_posts has php notice when not on CPT archive
- Duplicating event posts in wordpress
- When to use WP_query(), query_posts() and pre_get_posts
- Sort on meta value but include posts that don’t have one
- Can I exclude a post by meta key using pre_get_posts function?
- Should I use Pre Get Posts or WP_Query
- Using pre_get_posts with WP_Query
- Using pre_get_posts on true pages and static front pages
- Taxonomy: Why ‘with_front’ => false DOES NOT WORK?
- WP_Query orderby post__in remains ineffective in the Loop [closed]
- How to Change Order of Posts in Admin?
- How to add images to taxonomies?
- Media library to list images only user uploaded
- multiple orderby in pre_get_posts action
- Get url of product’s images (woocommerce)
- What is “main query”? [duplicate]
- Prevent pre_get_posts filter on specific post type
- Using pre_get_posts to rewrite search query to display posts from multiple taxonomies
- Custom Taxonomy and Tax_Query
- How to pass URL parameters for advanced taxonomy queries with multiple terms for one custom taxonomy
- sort child pages on admin
- Custom Table Column Sortable by Taxonomy Query
- Include and Exclude Taxonomies From Archives & Feeds Using ‘pre_get_posts’
- Custom search filter causes menu and query_posts problems
- Using meta_query on pre_get_posts to exclude a particular meta_key value
- Reduce or prevent calling of update_meta_cache
- How to add taxonomy filter on the query fly?
- Using multiple taxonomies to sort Custom Posts
- Assign posts to taxonomy terms instead of the taxonomy terms to posts?