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?
- Pagination with custom SQL query
- 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?
- ajax category filter
- 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 support multiple search terms query within one process?
- Recommended way to drop a pending query (in pre_get_posts)?
- 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
- SELECT * FROM $wpdb->posts WHERE ID > 160
- Removing posts from the returned wp_query. Cannot use object of type WP_Query as array
- Refine/Filter WP_Query Posts with jQuery or Ajax
- How To Get Some Data From WordPress Database Using WordPress $wpdb Query?
- How to apply filter inside a single wp_query?
- What is considered a default query for the request filter?
- When to add_filter() to Custom Query
- Select from wp_post and multiple meta_value from wp_postmeta
- Order by custom table and multiplication
- 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
- Using Ajax to load more posts | Help me change the wording on my button to notify the user
- How to create a WordPress Post Filter that users can use to filter posts by year?
- add_filter() depending on search term
- query_vars filter not working even though query string parameter is present
- 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
- wp_query ‘s’, search filter with pagination is not working
- 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
- Order by summing multiple values
- Display filtered results into custom page
- Applying posts_clauses filter to specific queries only
- Add class to first post in custom loop using post_class filter
- 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
- Is it possible to query from external database? [duplicate]
- Include post content of linked posts in search
- Changing the default wp_search_stopwords
- Getting additional columns from sql
- Filter post query to only show direct children of category
- Is it possible to add an argument to a custom function added to a filter hook?
- How to make posts unqueryable/unpublish posts where ACF relationship field is an unpublished post? [closed]
- Getting rid of unwanted nonSQL syntax characters when debugging a query
- Using post_where filter only on main query NOT sidebard new WP_Query
- Slow Query On Search
- Remove post type filter added by the plugin in the final query
- relation OR instead of AND – Filtered term ID’s in loop
- Can’t order the query result as given posts id’s array
- Randomly select one of last 3 posts
- filter posts by meta key with pagination
- meta_query weird behaviour, static int will work, but not user data
- Filter sub-category from checkbox form
- My combination of ‘post_type’ and ‘tax_query’ not working?
- SQL query injection with fifu image
- Passing a SQL query to the WP Query
- How to add a “base” filter for all posts visible to visitors on the site?
- WP_Query() not working as expected
- WordPress – Form does not filter the results of taxonomies
- Translating WP query into to SQL query
- How to search CPTs in draft using get_page_by_title()
- Custom category page with taxonomy filters
- get term objects and post objects in query
- How to set selected attribute on option after filter query?
- Calculating efficiently on large amount of data generated by wp_query
- Issue generating custom filter for cpt admin columns
- Include post_status check within $wpdb query
- Find by post_meta, then sort by post_meta, then sort by date (wp_posts)
- Custom query with post_class filter using current_post not working
- WP Query to order posts by multiple meta fields
- Filter WP_Query output before it is accessed (pre_get_posts)?
- Loop the posts between two dates selected using jquery datepicker
- query post based on comparison
- WP_Query with several meta_query-statements and order by meta_value
- wpdb LIKE request shows all database data
- Edit WordPress loop, taxonomies, & filter
- Woocommerce set loop_shop_columns to be 3 in the main shop page loop only and 4 otherwise
- List categories using WP_Query
- Add custom argument to WP_Query and modify SQL where clause
- I need to get all categories from a WP_Query
- Group By query based on Custom Field