Skip to content
Read For Learn
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP
Read For Learn
  • Database
    • Oracle
    • SQL
  • C
  • C++
  • Java
  • Java Script
  • jQuery
  • PHP

How to stop wp_postmeta from being called on archive and search pages?

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:

  1. Optimize WP Meta Query for large amount of post meta?
  2. Meta compare with date (stored as string) not working
  3. How metadata API works?
  4. WP_POSTMETA – What do these values mean inside the data structure?
  5. What type of index should I use for postmeta?
  6. How to create a meta_query to get all posts with a specific meta data?
  7. Compare meta_query with a Regular Expression and do a less-than operation on it
  8. $wpdb class updating meta_value using Ajax [closed]
  9. cleaning up safely wordpress wp_postmeta table
  10. Should I save this mulit dementional arary as one post meta?
  11. How to check if a post meta key/value pair already exists for a specific post
  12. get Insert id for meta field
  13. Filter posts by meta key
  14. Search post overlapping dates – meta_query with meta_key
  15. How can I query for posts using a date stored in post-meta?
  16. I can not display meta value in extras.php and template-tags.php
  17. Negative meta_query if storing multiple post_meta values with shared meta_key
  18. How to get posts by meta value as multi-dimensional array?
  19. Combine meta query and give a specific meta query a higher priority
  20. Is there any way to get all custom posts and all custom terms with it’s meta in few queries?
  21. Multiple meta key and value search in the query
  22. Multiple postmeta values to the same post_id/meta_key combination?
  23. Retrieve posts from meta key
  24. How to show specific meta keys of all posts in admin panel?
  25. How to create a link for wordpress meta datas?
  26. Cache metadata for set of posts
  27. How we insert values into database using metabox WordPress?
  28. How do I retrieve the slug of the current page?
  29. Most efficient way to get posts with postmeta
  30. Get posts by meta value
  31. Explanation of update_post_(meta/term)_cache
  32. How to extract data from a post meta serialized array?
  33. How to save an array with one metakey in postmeta?
  34. WordPress is stripping escape backslashes from JSON strings in post_meta
  35. How can I get the post ID from a WP_Query loop?
  36. Check if Post Title exists, Insert post if doesn’t, Add Incremental # to Meta if does
  37. Use REGEXP in WP_Query meta_query key
  38. How to update_post_meta value as array
  39. Adding meta tag without plugin
  40. What’s the point of get_post_meta’s $single param?
  41. What is the different between an attachment in wp_posts and an attachment in wp_postmeta?
  42. How to edit a post meta data in a Gutenberg Block?
  43. Set Alias for meta_query arguments in get_posts()
  44. Sanitizing integer input for update_post_meta
  45. post formats – how to switch meta boxes when changing format?
  46. Execute action after post is saved with all related post_meta records (data)
  47. Lack of composite indexes for meta tables
  48. Get a single post by a unique meta value
  49. if get_post_meta is empty do something
  50. How we get_post_meta without post id
  51. How get post id from meta value
  52. What is the code to get the download link for a product in WooCommerce?
  53. Safe to delete blank postmeta?
  54. advanced custom fields update_field for field type: Taxonomy
  55. update_post_meta not saving when value is zero
  56. Content hooks vs User hooks
  57. Getting attachments by meta value
  58. Ordering posts having multiple post-meta date fields
  59. Trying to get custom post meta through Jetpack JSON API [closed]
  60. How to update/insert custom field(post meta) data with wordpress REST API?
  61. Restrict post edit/delete based on user ID and custom field
  62. Custom Queries: Joining On Meta Values From Two Custom Post Types
  63. get_post_meta returning empty string when data shows in the database
  64. publish_post action hook doesn’t give post_meta_data
  65. Remove WordPress.org Meta link
  66. Remove post meta keys
  67. How to access the post meta of a post that has just been published?
  68. Why time functions show invalid time zone when using ‘c’ time format?
  69. Why is get_post_meta returning an array when I specify it as single?
  70. How Can I save multiple records in same meta key?
  71. How to update/delete array in post meta value?
  72. How to get all term meta for a taxonomy – getting term_meta for taxonomy
  73. Adding an assisting editor box to Post page
  74. Meta query interfering with orderby relevance
  75. WooCommerce conditional meta query
  76. delete unused postmeta
  77. Should I sanitize custom post meta if it is going to be escaped later?
  78. How to update single value in multi dimensional Post Meta?
  79. Add post meta based on another post meta value before publish post
  80. What is an efficient way to query based on post_meta?
  81. How do I retrieve multi-dimensional arrays from the wp_postmeta table, & display on a website?
  82. Front-end update_post_meta snippet displays white screen?
  83. WP_Query not working as expected for attachments and custom meta_query
  84. Query between two meta values?
  85. Save both current and new version of post meta
  86. I can’t set meta_key in my custom post type query
  87. Get Advanced Custom Fields values before saving [closed]
  88. Give extra post-meta to RSS feeds
  89. How to get meta value in wp_attachment_metadata
  90. Documentation for post meta
  91. WP REST API “rest_no_route” when trying to update meta
  92. Clean up output added via wp_head()
  93. List posts under meta_value heading
  94. Why am I getting an infinite loop with have_posts?
  95. get_post_meta – get a single value
  96. delete value 0 in post meta [closed]
  97. How to solve slow WordPress site caused by attachment_metadata
  98. Can I safely delete a record, manually, in the wp postmeta table?
  99. How can I create a WP_Query that returns posts where one meta_value
  100. How to store post meta in an array?
Categories post-meta Tags meta-query, optimization, post-meta
$wpdb: Counting posts corresponding to 3 terms in 3 different taxonomies
Why is minimum_args protected?

Recommended Hostings

Cloudways: Realize Your Website's Potential With Flexible & Affordable Hosting. 24/7/365 Support, Managed Security, Automated Backups, and 24/7 Real-time Monitoring.

FastComet: Fast SSD Hosting, Free Migration, Hack-Free Security, 24/7 Super Fast Support, 45 Day Money Back Guarantee.

Recent Added Topics

  • Bug in translation system: load_theme_textdomain() returns true, files are available and accessible but the language defaults to english
  • Custom Elementor controls not appearing in the widget Advanced tab using injection hooks
  • Get the name of the template/*html file used
  • Trying to Add Paging to Single Post Page
  • Sharing media files between live and staging servers
  • How to display the description of a custom post type in the dashboard?
  • Critical error on image display
  • Copying WP data and files into new install?
  • How to determine the DirectAdmin WordPress backup date?
  • How to get list of ALL tables in the database?
© 2026 Read For Learn
  • Database
    • Oracle
    • SQL
  • algorithm
  • asp.net
  • assembly
  • binary
  • c#
  • Git
  • hex
  • HTML
  • iOS
  • language angnostic
  • math
  • matlab
  • Tips & Trick
  • Tools
  • windows
  • C
  • C++
  • Java
  • javascript
  • Python
  • R
  • Java Script
  • jQuery
  • PHP
  • WordPress