As @bonger said, let your filters accept a second argument, which will be the instance of WP_Query
that’s executing the filter, and check it is indeed the main query for an event:
function single_posts_fields( $sql, $wp_query ) {
if ( $wp_query->is_main_query() && $wp_query->is_singular( 'event' ) ) {
// Do your stuff
}
}
add_filter( 'posts_fields', 'single_posts_fields', 10, 2 /* Number of accepted arguments */ );
function single_posts_join( $sql, $wp_query ) {
if ( $wp_query->is_main_query() && $wp_query->is_singular( 'event' ) ) {
// Do your stuff
}
}
add_filter( 'posts_join', 'single_posts_join', 10, 2 /* Number of accepted arguments */ );
Related Posts:
- Whats the difference between post_limits and pre_get_posts?
- WP_Query with “post_title LIKE ‘something%'”?
- Pagination with custom SQL query
- Use REGEXP in WP_Query meta_query key
- How to list some posts first in the loop based on post id
- How to add taxonomy filter on the query fly?
- Using OR conditions in meta_query for query_posts argument
- WP_Query – filter or directly?
- What is the most efficient way of querying posts based on visits and date for current day?
- Is it possible to wrap Geo Location search around WP_Query?
- Changing Posts Per Page and offset with pre_get_posts
- ajax category filter
- Is it possible to select against a post’s parent’s fields with WP_Query?
- How to order posts tag by tag?
- Overriding The Loop with filter or hook
- Custom query incorrectly returning everything [closed]
- Extending WP_Query — Optimise SQL query
- WP Rest API v2 return posts with specific tag
- Ignore a filter on the media library
- How to make an activities stream mixing posts and comments?
- How to support multiple search terms query within one process?
- SQL Statement generated by WP_Query not producing expected results
- What is an efficient way to query based on post_meta?
- SQL query equivalent to WP User Query
- Recommended way to drop a pending query (in pre_get_posts)?
- How to get any tag ID
- how to retrieve specific product attribute value in an sql query?
- Which filter/action hook gets triggered after a query has been performed?
- Filter WordPress posts by between parameter
- SQL User Query by Multiple Roles using PHP
- Advanced WP Query hogs the SQL server
- Remove ellipsis from the excerpt retrieved using get_the_excerpt()
- SELECT * FROM $wpdb->posts WHERE ID > 160
- Removing posts from the returned wp_query. Cannot use object of type WP_Query as array
- How to implement time filter to show random post 1 month for one category and 3 months for other categories
- What’s the point of the query_vars filter?
- Refine/Filter WP_Query Posts with jQuery or Ajax
- How To Get Some Data From WordPress Database Using WordPress $wpdb Query?
- Use ‘parse_query’ filter to show posts that from multiple criteria
- Query post with meta_query where date is not in future
- How to apply filter inside a single wp_query?
- What is considered a default query for the request filter?
- Using apply_filters(‘the_content’, $custom_query->post_content) alters output
- Modifying the Search Results
- WP User Query get all authors with last name starting with specific letter
- When to add_filter() to Custom Query
- Select from wp_post and multiple meta_value from wp_postmeta
- Order by custom table and multiplication
- How to correctly pass values to wpdb->prepare()?
- Query total number of posts
- How to add post_distinct filter to WP_Comment_Query?
- Sort users by “birthday” using WP_User_Query
- $wpdb select date range of posts
- How To Fix WP Query Returns Results But Shouldn’t?
- Using Ajax to load more posts | Help me change the wording on my button to notify the user
- List of the years with posts presented
- How to use filter hook “the_posts” with a function that refers to $this?
- How to create a WordPress Post Filter that users can use to filter posts by year?
- add_filter() depending on search term
- SQL: What is wrong with the following query (generated by WordPress WP_Query, ordering prices)
- query_vars filter not working even though query string parameter is present
- Slow WP_Query for custom post type
- Complex WP SQL Query
- Query that loads a custom type AND posts whose ids are not inside those custom types custom fields
- How do I run through a WordPress loop called from a filter function?
- Optional Meta Query
- Order by title without taking into account ‘the’
- How can I filter by slug depending on language selection
- Sorting events by descending date, and ascending time if multiple events on a date
- wp_query ‘s’, search filter with pagination is not working
- Editing the default wordpress search
- How to filter, restrict and return posts based on custom user meta information
- Bypass “supress_filters” in WP Query
- How to use the query hook/filter?
- WP Query related posts by tags
- Filter posts in category archive page by year using a dropdown
- Order by summing multiple values
- Display filtered results into custom page
- How to extract specific post
- Woocommerce – Changing the order of the upsell products [closed]
- Changing sort order for presentation by Jetpack infinite scroll
- Applying posts_clauses filter to specific queries only
- Add class to first post in custom loop using post_class filter
- WP_Query with different postmeta filter for each categories
- Slow WP_Query with ‘OR’ on meta_query
- Include data from custom table in WP_Query
- Add posts to WP Query object
- wordpress ajax relationship query
- How to alter local query, not main query [duplicate]
- How to filter a query by date in a shortcode?
- How can I allow sticky posts but cap the query to 1 post?
- how to access query string in wordpress?
- How to pass orderby params to $wpdb->prepare()?
- Filter Custom Taxonomy Posts
- Debugging wp_query orderby for taxonomy
- Is it possible to query from external database? [duplicate]
- Include posts from some categories while excluding from others
- Include post content of linked posts in search
- Make a SQL query with wpdb in WordPress
- Changing the default wp_search_stopwords