Querying this many posts is dangerous and you can ( and do ) take the site down. If you absolutely have to do this, you need to adjust your query to be more performant.
If you’re just needing the link then add 'fields' => 'ids'
to your params – this will only return the post ID and not the whole Post object. You can then use the ID to get the permalink, title etc.
If you’re not going to paginate, then use 'no_found_rows' => true
this will stop WordPress from running expensive SQL CALC queries to get the total number of posts that the query retrieves.
You should 100% cache the results of this query using the Transient API this will allow you to return cached HTML instead of rebuilding this query every time someone hits the page.
Related Posts:
- When to use WP_query(), query_posts() and pre_get_posts
- WP Query Args – Title or Meta Value
- WordPress Pagination Not Working – Always Showing First Pages Content
- Whats the difference between post_limits and pre_get_posts?
- WP query taxonomy input differs to output?
- Query WooCommerce orders where meta data does not exist
- How to get Page/Post Gallery attachment images in order they are set in backend using WP_Query()?
- What exactly does the ‘s’ parameter search for in WP queries?
- WP_Query min and max values
- get_posts not finding argument: post_name
- get query’s query string
- Show only oldest post by author
- assign 2 $args to one wp_query
- Revolution Slider Orderby Two Custom Fields
- Calling a custom excerpt function in a local loop
- Dynamically Override Fancy Title – Part II
- Transient pagination not working properly
- How to run query inside a class with namespace?
- Which filter/action hook gets triggered after a query has been performed?
- Modify existing query and change order of posts
- Why does the_content not work like others for a set post id?
- pre_get_posts filter meta_query without conflicting existing meta_query
- How would I format a query that depends on post parent taxonomy
- Minimising Database Queries when using Advanced Custom Fields
- Rewrite rule to prettify two $_GET variables while in a new endpoint from a page
- Creating a custom search for a specific post type
- How to add post_distinct filter to WP_Comment_Query?
- WP_Query Group by Author and Order each group DESC
- List only posts from specific category on category page
- Most popular post for last 7 days
- WP Pagination on Posts Search Results Page resulting from AJAX WP Query
- How to avoid wp_query returning the same post I’m on in results?
- Query multiple meta values
- Why isn’t my multiple orderby working?
- WP_Query ignoring tax_query when is_singular
- WP_Query() order by post content lenght?
- Query posts without meta preload
- Excluding pages in WP_query using ACF
- reset to main loop doesnt work
- Applying posts_clauses filter to specific queries only
- Pagination on static Posts page
- WP_Query : Search and Filter Using custom field AND/OR custom taxonomy
- Query all posts if multiple meta key don’t exist
- meta_compare not comparing whole integer
- WP_Query – Object manipulation vs WordPress functions
- WP_Query with rewind_posts creates duplicate titles
- Transients with dynamic WP_Query
- Custom WP query with polylang term
- All posts returned when author of 0 is queried
- Merge two search functions for custom post type
- WP_Query – Accessing MetaValue from Query Result
- problems with comments_number()
- Trying to retrieve random post, getting a page
- get_the_terms – but only show 4 Posts
- Does WordPress have something like Drupal’s DB API?
- PHP – Loop custom post type categories within jQuery Tabs
- How order posts from category by date and comment count?
- Get a list of ACF Repeater-Fields as array
- query_vars empty when using custom url with custom rewrite rule
- Get query results with a page title
- Show single posts date, in a page of posts
- Post archive for certain post format
- How to filter multiple queries with search?
- Compare “Main” post ID to ID inside wp_query loop
- Attempt to display site authors in a carousel – User Image not Outputting inside li tags
- Add AJAX “Load more” on custom query block
- problem with the loop
- Order WP_Query by meta_key priority when ‘OR’ relation used for multiple meta values
- Why my query is not “Main_query”?
- Filter sub-category from checkbox form
- Facing problem with tax_query results
- How to add a “base” filter for all posts visible to visitors on the site?
- sanitize_post() is not sanitizing Post Object
- wp query search multi terms
- How to get top rated posts using wp query?
- Unusual high query of user meta data
- Woocommerce featured products query no longer working
- add action for wordpress query at a specific position
- How to query wordpress with array of meta_values?
- WP Query Meta Query
- Updating an intensive wp_query result once daily
- Custom WP_query and integrating into theme file
- Empty ‘terms’ in ‘tax_query’ returns an empty array
- Get newest value of an array
- Filter custom post type by custom taxomony
- Return a single custom post from multiple meta queries
- ordering and optimizing functions
- Why does order ASC break offset in WP_Query?
- new WP_query using custom fields
- Having Trouble Running Query From Shortcode Using Tribe’s Events Plugin
- Change ‘post_modify’ with a query
- An archive page without post format (just standard post)
- Dynamically create array from page title
- Ordering Custom WP_Query loop by meta key value with pagination
- paginate_links() on page (shortcode output)
- WordPress Query Returning Every Post
- Pagination showing same posts despite changing page
- shortcode with $atts with strange results
- Query custom post types by meta field in a term from custom taxonomy
- Display Featured image from custom post type category (custom taxonomy) wise