First, don’t use is_main_query()
function (method is ok). It tells something absolutely different from what you would think it does — was the main query overridden.
As far as I remember, there is no clean solution to this since WP doesn’t have a concept of explicitly passing context to a specific template or template part.
Since WP’s way hinges primarily on globals, the “fitting” (if dirty) approach might be to pass the information in same fashion — through a global variable(s) of your own.
Related Posts:
- Pass the same object to multiple widgets in a template with one query
- Unable to paginate a custom page query
- When should you use WP_Query vs query_posts() vs get_posts()?
- order by numeric value for meta value
- Using a custom WP_Query with get_template_part loop
- How to query for most viewed posts and show top 5
- WP_Comment_Query pagination, delving into the unknown
- Sort posts by category name and title
- Custom WP_Query order by post_meta and (author) user_meta
- WP_Query for WooCommerce Products
- Perform query with meta_value date
- Add and in the header while looping over custom query in page template
- Highlighting Sub topic in a post?
- Single page theme
- How to speed up wp_query, took more 5s to run against 100k posts
- WP_query category__in not working, only pulls from first category
- Splitting the main query in multiple loops with query_posts and/or pre_get_posts?
- How do you query wordpress posts using a math formula between multiple meta field values?
- Custom Post order for homepage
- Page navigation doesn’t show when query category
- Meta Query for specific months
- Different string for specifed post type on posts listing at homepage
- if/else on custom query gives 200 OK when condition not met?
- Minimize database queries to user tables?
- Query all published post AND attachment with specific mime type
- only delete post within query / for each statement (front end)
- Add quicklink to in the Admin posts page where I can query by a meta_key
- Get all products which have both product category
- unable to retrive parent page information
- How to detect if query is runned from widget?
- How to display user order by role
- How to use the query hook/filter?
- WP Query related posts by tags
- Order by summing multiple values
- add_filter(‘query_vars’) not working in custom template
- Check if loop has any categories?
- How to get list of posts from permalinks?
- Is there a reason why Pages are not publicly_queryable?
- Check return value of get_posts
- Exclude some authors from query
- Query only the posts with a post format of “audio”
- get_template_part causes 500 error
- pre_get_posts – Trying to get property of non-object warning
- WordPress query posts with multiple post_meta data
- Get a list of posts by specific category
- How to check the array values, what WP_Query has brought to me?
- How to add custom meta to ‘pre_get_terms’?
- Shortcode for custom query not returning results when attributes are added
- Should I reset $wp_query?
- Update query for wp_posts and wp_postmeta
- Get posts in taxonomy randomly
- Get specific ACF key and value from all posts – no access to DB
- Write WP Query that selects posts that are part of the same two categories
- I am officially missing something about transient posts
- Insert images into wordpress post with a query
- WP_Query meta compare must include ALL array values
- Start Query from 2nd Post without offset
- Disable (or limit) queries when certain content (or data) is not needed (or showed)
- Display upcoming events in the next 30 days by querying posts with timestamp in custom meta
- Prioritising and Ordering Posts By Category Name Using A Custom Loop
- Filter products on category AND tag
- pre_user_query vs pre_get_posts
- Adding nofollow to all the post links in get_posts with pre_get_posts or WP_Query
- Meta query orderby meta_value_num sorting by role first
- WP_Query & Duplicate entries
- How to query users by post count no less than 10
- Add to search posts query array with post IDS which will appear first
- Query by meta value (add a dropdown of all values)
- WP_Query about meta_key and its array value
- Create global array to compare inside a query
- How to show terms from another taxonomy
- My entry results are not consistently alphabetized
- Ignoring ‘a’ when sorting posts
- Custom query for tag and custom tag from 2 post type
- wpdb get_results() returns only 2 rows
- Filter posts/pages by user_role array
- WP_Query secondary query failing
- Search Functionality broken by the wp 4.2 update
- Issue attempting a wp_query_posts with tags
- Passing query variables to a custom page template
- add_query_vars does not work
- Divide WP_Query posts by date & post type
- Retrieve posts in custom post type and specific taxonomies
- How return normal search result using wp_ajax action for wordpress
- New WordPress WP Query using posts from certain categories
- Custom post types loop on a page template
- Get the number of rows from $wpdb->get_results not working
- Parsing External Table Arguments
- Get Child Custom Post Content on Single.php?
- difference between methods of query
- Query posts by meta value and sort by another meta key
- How much does $wpdb->prepare(), then $wpdb->query() VS straight $wpdb->query(), can slow down the load time of whole page
- how to use transient method?
- Pre_get_post on CPT archive page
- Get posts that were most recently tagged
- A Depth Like Parameter For “get_posts”
- Search query alteration not working for meta values
- on attachment.php, how to display previous and next attachment links that follow the same order as a custom WP Query
- Advanced Search – Is this possible?
- Use value from meta key array for use in WP_Query