add_filter('pre_get_posts', 'customize_query');
function customize_query($query) {
if($query->is_main_query() && ($query->is_search() || $query->is_archive()) {
$query->set('update_post_meta_cache', false);
$query->set('update_post_term_cache', false);
}
}
Then wordpress will make 2 less queries for those pages & then you can use the $wpdb object to write custom queries.
Related Posts:
- Optimize WP Meta Query for large amount of post meta?
- Meta compare with date (stored as string) not working
- How metadata API works?
- WP_POSTMETA – What do these values mean inside the data structure?
- What type of index should I use for postmeta?
- How to create a meta_query to get all posts with a specific meta data?
- Compare meta_query with a Regular Expression and do a less-than operation on it
- $wpdb class updating meta_value using Ajax [closed]
- cleaning up safely wordpress wp_postmeta table
- Should I save this mulit dementional arary as one post meta?
- How to check if a post meta key/value pair already exists for a specific post
- get Insert id for meta field
- Filter posts by meta key
- Search post overlapping dates – meta_query with meta_key
- How can I query for posts using a date stored in post-meta?
- I can not display meta value in extras.php and template-tags.php
- Negative meta_query if storing multiple post_meta values with shared meta_key
- How to get posts by meta value as multi-dimensional array?
- Combine meta query and give a specific meta query a higher priority
- Is there any way to get all custom posts and all custom terms with it’s meta in few queries?
- Multiple meta key and value search in the query
- Multiple postmeta values to the same post_id/meta_key combination?
- Retrieve posts from meta key
- How to show specific meta keys of all posts in admin panel?
- How to create a link for wordpress meta datas?
- Cache metadata for set of posts
- How we insert values into database using metabox WordPress?
- How do I retrieve the slug of the current page?
- Most efficient way to get posts with postmeta
- Get posts by meta value
- Explanation of update_post_(meta/term)_cache
- How to extract data from a post meta serialized array?
- How to save an array with one metakey in postmeta?
- WordPress is stripping escape backslashes from JSON strings in post_meta
- How can I get the post ID from a WP_Query loop?
- Check if Post Title exists, Insert post if doesn’t, Add Incremental # to Meta if does
- Use REGEXP in WP_Query meta_query key
- How to update_post_meta value as array
- Adding meta tag without plugin
- What’s the point of get_post_meta’s $single param?
- What is the different between an attachment in wp_posts and an attachment in wp_postmeta?
- How to edit a post meta data in a Gutenberg Block?
- Set Alias for meta_query arguments in get_posts()
- Sanitizing integer input for update_post_meta
- post formats – how to switch meta boxes when changing format?
- Execute action after post is saved with all related post_meta records (data)
- Lack of composite indexes for meta tables
- Get a single post by a unique meta value
- if get_post_meta is empty do something
- How we get_post_meta without post id
- How get post id from meta value
- What is the code to get the download link for a product in WooCommerce?
- Safe to delete blank postmeta?
- advanced custom fields update_field for field type: Taxonomy
- update_post_meta not saving when value is zero
- Content hooks vs User hooks
- Getting attachments by meta value
- Ordering posts having multiple post-meta date fields
- Trying to get custom post meta through Jetpack JSON API [closed]
- How to update/insert custom field(post meta) data with wordpress REST API?
- Restrict post edit/delete based on user ID and custom field
- Custom Queries: Joining On Meta Values From Two Custom Post Types
- get_post_meta returning empty string when data shows in the database
- publish_post action hook doesn’t give post_meta_data
- Remove WordPress.org Meta link
- Remove post meta keys
- How to access the post meta of a post that has just been published?
- Why time functions show invalid time zone when using ‘c’ time format?
- Why is get_post_meta returning an array when I specify it as single?
- How Can I save multiple records in same meta key?
- How to update/delete array in post meta value?
- How to get all term meta for a taxonomy – getting term_meta for taxonomy
- Adding an assisting editor box to Post page
- Meta query interfering with orderby relevance
- WooCommerce conditional meta query
- delete unused postmeta
- Should I sanitize custom post meta if it is going to be escaped later?
- How to update single value in multi dimensional Post Meta?
- Add post meta based on another post meta value before publish post
- What is an efficient way to query based on post_meta?
- How do I retrieve multi-dimensional arrays from the wp_postmeta table, & display on a website?
- Front-end update_post_meta snippet displays white screen?
- WP_Query not working as expected for attachments and custom meta_query
- Query between two meta values?
- Save both current and new version of post meta
- I can’t set meta_key in my custom post type query
- Get Advanced Custom Fields values before saving [closed]
- Give extra post-meta to RSS feeds
- How to get meta value in wp_attachment_metadata
- Documentation for post meta
- WP REST API “rest_no_route” when trying to update meta
- Clean up output added via wp_head()
- List posts under meta_value heading
- Why am I getting an infinite loop with have_posts?
- get_post_meta – get a single value
- delete value 0 in post meta [closed]
- How to solve slow WordPress site caused by attachment_metadata
- Can I safely delete a record, manually, in the wp postmeta table?
- How can I create a WP_Query that returns posts where one meta_value
- How to store post meta in an array?