If you can alter a query before it runs, then do so and save the database some work. You might be able to alter the query with query->set()
and if not you can use the posts_where
, posts_fields
, etc filters. It is hard to say whether any of that is best for you without more information.
Edit:
Another question, what kind of ‘page’ is this loading on? Here is my guess: you created a ‘Page’ from wp_admin->Pages, and probably assigned a custom built page template. If that is the case you probably can’t mess with the main query as its job is going to be to load the ‘Page’ you created, which means you seem to be on the right track with creating the new query.
Related Posts:
- Set Alias for meta_query arguments in get_posts()
- How can I use order_by to order by two meta_keys without excluding posts that don’t have those keys initialized?
- Loop within a loop?
- WP_Comment_Query pagination, delving into the unknown
- Getting all user metadata from user
- How to get posts in different language from WPML Plugin [closed]
- Limit WP_Query to only X results (total, not per page)
- WP_Query meta_query where meta value ends in space
- How to disable main query?
- Highlighting Sub topic in a post?
- wp_query for the first sticky, then display the rest of the posts excluding the first sticky
- Use post__in and post__not_in together?
- WP_Query with many meta_query arguments taking a long time to load
- how to retrieve specific product attribute value in an sql query?
- How to user WP_Query to lower the number of queries
- Slow speed and high CPU usage for my code. How to improve it?
- Multiple queries on Home Page – page load/site speed issue
- Compile two queries to one set of results?
- how do i combine keyword search and taxonomy in a WP_query $args array Worpresss [closed]
- query attachments of parent page if attachments of current page are smaller than …
- WP_Query tax_query problem
- Only display authors who have posts
- Update Loop with Form
- How to retrieve current page WP_Query arguments?
- Query Custom Post Type Order By Taxonomy Field
- Setting get_queried_object
- Changing WP_Query params with url Query Var
- From where is archive.php getting its posts?
- Wp redirect to url with ampersand string
- How can I make WP_Query get posts that have a tag but also have random other tags?
- Change query based on post type while staying in loop
- Access WordPress query by index number outside the loop
- Custom Pagination Layout for Elementor widget
- Pagination outside of loop
- Multisite – Global CPT – advices?
- $WP_Query: How to display excerpt on first post only
- How to properly reset a nested WP_Query query
- Gallery shortcode numerical sorting
- Is there a reason why Pages are not publicly_queryable?
- Check return value of get_posts
- How Can I Change The Tax Query For The Main Loop For Taxonomy Archives?
- The most effective way to split by post type in custom query?
- Does meta_value (array) work with ‘orderby’?
- Get a list of posts by specific category
- WordPress Query String: get_posts(‘cat=5’) vs WP_Query( ‘cat=5’) vs URL: /site/?cat=5
- WP_Query – Adding “offset” posts to the end of the loop
- wp_query is showing posts from other categories
- Multiple wordpress queries with nested output (odd – even)
- it’s possible make a WP_Query with math operations?
- show posts with range meta key
- how to write wordpress query for multiple metakeys checking?
- Using a Shortcode to List Posts from Multiple Categories
- How to display a list of posts in same child category as current post
- querying posts with a custom status
- wp_query on page template not working (Genesis framework)
- Display post meta conditionally based on it’s value
- How can i show pagenavi in my author.php?
- Randomly select one of last 3 posts
- Query multiple meta key values for template
- Using WP_Query with multiple loops on one page in search.php
- WP_Query Pagination
- Order by post meta not working with pre_get_posts filter
- ACF: How to query for a given value count of an array like field? (e.g.: How many rows has a `flexible_content` field?)
- is_user_logged_in not working from WP-API (wp-json)
- WordPress private post won’t display to other admins
- Only show tag with the same id as the post
- Search Exact on WordPress – Relevannsi Solution Not Working
- ACF: How can I publish values of ACF fields in a loop while using wp_query?
- Sort by price wpdb
- WP_Query random ordering not working since 5.4
- Show a message if there are no active posts in category
- Get authors list and sort them by recent posts
- Where my home page and font options has gone?
- How to get the latest post list (of the parent custom custom type)
- Problem with my loops
- 404 page on custom search pagination
- next_posts_link not visible on first page
- Query string order by custom field
- Paging works correctly on local version, but not live?
- Create global array to compare inside a query
- Pagination not working in custom loop WP_Query
- Multiple wpostmeta.meta_key
- Hi , i am trying to set the post for 24 hours and with it will be changed
- Own query vars are not displayed
- Show full category tree for a year with all post titles?
- Trying to use “Medium” featured image for custom post type on home page
- Filter posts/pages by user_role array
- Display images with same specific value?
- WP_Query with meta_value_num and meta_query not paged correctly
- I need value of saved meta to display next to the post it is associated with
- Post Query not working after updating to 4.1
- Search Query that Includes Custom Table
- Pagination with WP_Query not working
- new WP_Query based on average values of meta fields
- How return normal search result using wp_ajax action for wordpress
- Custom post types loop on a page template
- Can’t seem to get an else statement correct? [closed]
- query_vars category_name only display one catgory out of multiple categories
- WordPress extremely slow when using get_posts with multiple meta_query relations
- Search results stuck on page 1