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

Which is faster wpdb & get_row or wp_query & ge_post_meta?

You should always use get_post_meta. Your attempt to micro-optimise using a raw SQL query will reduce not improve performance.

When you fetch a post, WordPress bulk fetches its meta for performance reasons, so if you used get_post_meta it would already have the answer in memory. If your site has an object cache then it would remember it from previous requests too.

Whereas if you used raw SQL, not counting that WordPress itself uses SQL too, you would have lots of small database queries that you have to wait for, even if WordPress already knows the value of that meta.

You’ll also be introducing plugin compatibility issues as none of the filters get_post_meta runs will be available, and some plugins short circuit these values or manipulate them to implement features.


If you’re wanting to build your own table, know that you’ll be giving up all the optimisations WordPress has, and there is no guarantee it will be faster. Having a custom table doesn’t make thing faster, not unless it’s designed correctly with appropriate indexes to be fast for particular kinds of queries. You’re likely to find the table is actually slower.

Generally though, the pivotal piece of information most WP developers are unaware of that impacts significantly on performance, is that the post meta table is optimised for finding values when you already know the post ID/key. It is very poor at searches and filtering, aka find all posts that have a key with this value, or does not have that value. This is why taxonomies exist, and why tags/categories are not stored as post meta. Taxonomy tables are optimised for finding/filtering/searching for posts.

If you find yourself needing meta_query in your WP_Query arguments then consider changing those values to custom taxonomies and terms as meta_query can be extremely slow, and its performance degrades quickly as the post meta table grows in size.

Related Posts:

  1. Return only Count from a wp_query request?
  2. Use REGEXP in WP_Query meta_query key
  3. What is the most efficient way of querying posts based on visits and date for current day?
  4. Is it true $wpdb->get_results is faster than WP_Query in most cases?
  5. Slow SQL_CALC_FOUND_ROWS Query
  6. Stop all SQL_CALC_FOUND_ROWS wordpress queries
  7. How to count post meta key values for all posts in database
  8. Group posts by meta_key
  9. Would this post meta be better added to the post table rather than post_meta table
  10. Get the Plugin Which Triggered a MySql Query in WordPress?
  11. Mysql query LIKE not working
  12. Select from wp_post and multiple meta_value from wp_postmeta
  13. Improve wp query perfomance on large db
  14. Order by custom table and multiplication
  15. Performance when getting post meta for post retrieved by meta value
  16. Using hook to use DISTINCT in a wp_query
  17. How to increase load time of an archive/search page (WP_Query)
  18. Query most popular terms by taxonomy over 2 week period
  19. WordPress query posts with multiple post_meta data
  20. Disable (or limit) queries when certain content (or data) is not needed (or showed)
  21. get_var is neither a string, integer, or array …?
  22. update_post_meta performance in a loop woocommerce
  23. update_post_meta performance in a loop woocommerce
  24. Query postmeta based on meta_value, return array of post_id
  25. Optimising amount of calls to custom fields
  26. How to count post meta key values for all posts in database
  27. Different sql queries count indicator on the main page [closed]
  28. How to only display posts whose meta_value field is not empty?
  29. How to print the excuted sql right after its execution
  30. Can wp_query return posts meta in a single request?
  31. order by numeric value for meta value
  32. How do I query for posts by partial meta key?
  33. Pagination with custom SQL query
  34. WordPress retrieving meta data for all custom post types in list view
  35. Order by optional meta key?
  36. Order by DESC, ASC in custom WP_Query
  37. How to prevent execution of default query, while preserving ability to use WP_Query in template?
  38. meta_query: using BETWEEN with floats and/or casting to DECIMAL
  39. Reduce or prevent calling of update_meta_cache
  40. Is there a way to extend WP_query so Custom Post Types can have properties?
  41. Differences Between WP_Query() and get_posts() for Querying Posts?
  42. how does $wpdb differ to WP_Query?
  43. Should I use Transients with W3 Total Cache APC Caching? [closed]
  44. find a random blogid across my multisite network that has at least one post published
  45. Getting attachments by meta value
  46. WP_Query displaying ALL posts
  47. Get posts by menu ID
  48. Query causing load because of SQL_CALC_FOUND_ROWS post counting?
  49. meta_query where value is equal to given value
  50. Query Custom Meta Value with Increment
  51. WP-CLI How to generate a list of posts with corresponding meta values
  52. Use WP_Query with a custom SQL query
  53. get_the_title($postID) OR get_the_title()?
  54. How to make an activities stream mixing posts and comments?
  55. What is an efficient way to query based on post_meta?
  56. How can I connect to another WP database and use WP_Query?
  57. WP_Query not working as expected for attachments and custom meta_query
  58. SQL query equivalent to WP User Query
  59. What’s wrong with this WP query?
  60. How should I use posts_where to change meta_value from a string to integer?
  61. How to search for posts IN OR title OR content OR author?
  62. How to solve slow WordPress site caused by attachment_metadata
  63. How can I create a WP_Query that returns posts where one meta_value
  64. WordPress altering my custom query, How to fix it?
  65. WP_Query hit max joins… How else can I build a search function that uses custom fields?
  66. WP Meta Query for some meta (array) values
  67. Get number of comments after modifying comment query
  68. How to change a custom query into a standard loop?
  69. WP Query post meta value
  70. Custom URl parameter
  71. query posts in functions.php and update a field
  72. Compile meta values from custom loop into array and then calculate sum total
  73. How to get sum of meta_values of a meta_key in wp_query according to conditions
  74. how to fire join query with post_meta
  75. Slow speed and high CPU usage for my code. How to improve it?
  76. Multiple queries on Home Page – page load/site speed issue
  77. How to count data records in wordpress which have same meta_value in wp_postmeta table?
  78. Triple meta_key on custom SELECT query
  79. Order By Multiple Meta Fields
  80. Best approach to create Hot and Trending sections
  81. meta_query on a date range using an array of values
  82. WP_Query Performance Issues with meta_query
  83. WP_Query, custom sort and custom filter
  84. Should close $wpdb via $wpdb->close()
  85. How to speed up wp_query, took more 5s to run against 100k posts
  86. Database slowdown after update to 3.4.1
  87. SQL User Query by Multiple Roles using PHP
  88. Order posts by meta value and Date
  89. Efficient way to update multiple post meta
  90. WordPress Query is taking more then 20 second and stuck on creating index
  91. $wpdb->insert inserting two rows in database
  92. How to make orderby ‘meta_value_num’ OPTIONAL?
  93. Too many posts cause slow load when paginating
  94. Query Posts depends on custom field inside repeater field using acf
  95. How To Get Some Data From WordPress Database Using WordPress $wpdb Query?
  96. Detect featured image among the attached images
  97. Query post with meta_query where date is not in future
  98. How would I format a query that depends on post parent taxonomy
  99. Minimising Database Queries when using Advanced Custom Fields
  100. How to get posts on a specific date – WP Query
Categories wp-query Tags mysql, performance, post-meta, wp-query, wpdb
Correct Way To Make Changes To A WordPress Theme
is $wpdb->get_results() safe enough

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