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

$post->post_meta not pulling any post in wordpress/php

Your code is interfering with the internal structure of WP_Query and WP_Post, and making assumptions about how it works. This is extremely unusual, and not best practice when developing with WordPress.

Case in point, officially there is no post_meta member variable on that class ( https://developer.wordpress.org/reference/classes/wp_post/ ). That’s not how you fetch a posts meta key/values.

Instead, use a standard post loop, and standard API calls.

Here’s what a standard WP_Query post loop should look like:

$args = [
    // parameters go here
];
$query = new WP_Query( $args );
if ( $query->have_posts() ) { 
    while ( $query->have_posts() ) {
        $query->the_post();
        // display the post
        the_title();
        the_content();
    }
    wp_reset_postdata();
} else {
    echo "no posts were found";
}

Note that a standard post loop lifecycle happens, as well as all the expected hooks. You can do work inside the while loop for each post. For example, fetching all the post meta. To do that, use the get_post_meta function:

$all_meta = get_post_meta( get_the_ID() );

It might be tempting to think that a WP_Post object follows the naive OO dream of an all encompassing API for posts, a one-stop representation of a single post and all the things that there is to know and can be done about it. But in reality it’s a data container. You won’t find class methods or methods of sub-classing it.

Additionally, by poking around and directly accessing the internal data structures, you bypass a lot of functionality and risk your code being broken in the future. For example post meta gets fetched in advance and stored in WP_Cache to avoid query duplication. There are also filters that allow plugins and other code opportuniities to make changes or fix things.

Related Posts:

  1. Query all posts where a meta key does not exist
  2. Meta query with boolean true/false value
  3. Get post with multiple meta keys and value
  4. How Do I Use WP_Query to Run This Database Query as Search Result?
  5. Can’t sort order of wp_query with 2 meta keys
  6. Query for posts from any post type but only add instock products
  7. WordPress Orderby Numeric Value Not Working
  8. orderby in custom WP Query does not work
  9. Display custom post type from dynamic custom field
  10. WordPress request fiter order by related post’s post_title
  11. Displaying a div from an assigned meta_value when on a page
  12. How to get specific post meta by title or id
  13. WP_Query of custom post type sorted by meta_key has unexpected results
  14. Returning a custom content types with meta values
  15. WP_Meta_Query object with conditionals
  16. How to retrive Custom Post Type Meta Fields in Custom WP_Query
  17. After inserting new post with wp_insert_post() the post is not visble to WP_Query, but the same WP_Query works for post inserted from wp-admin panel
  18. Use WP_query to match post types based on custom field values
  19. How to sort by multiple values in a nested WP_Query
  20. Custom meta fields not showing up in WP_Response Object via custom endpoint
  21. How to get post by meta value
  22. How do I get all authors posts of a custom post type outside loop
  23. Linking posts together with Advanced Custom Fields “both ways”
  24. How to get Current week and current date record wp query
  25. How to get post meta for custom post type and taxonomy
  26. get_post_meta for Custom Post Type ( CPT )
  27. WordPress custom post type
  28. Custom Post Type meta oembed html output resulting in WSoD
  29. Values inside a custom field to determine which category posts to display
  30. Querying meta values within an array
  31. Quering a post object based on another related post object
  32. Wp_query: sort by PHP variable
  33. WP_Query most viewed posts, in multiple Post Types, last 30 days, excluding a specific taxonomy term
  34. Custom-Posttype & Custom Taxonomy WP_Query
  35. Crafting WP_Query array, sort by date
  36. Custom loop with multiple taxonomy queries
  37. Return one unique custom post type result when it shares a custom taxonomy in WP_QUERY?
  38. How to implement a Google map store locator
  39. Converting the_content string to an array?
  40. forming WP_Query for posts of all post types but from specific categories
  41. Get latest 3 posts from multiple CPT in one query
  42. Deleting Custom Posts & Meta Data on Uninstall
  43. Loop to fetch 3 post_thumbnail instances from 3 most recent custom post types named “portfolio”
  44. Widget: Custom Post Type Post Listing Dropdown on Admin Side
  45. Display upcoming Events for next 7 Days
  46. Post image in WordPress not appearing on home page
  47. How do I create an archive page as a including metadata?
  48. Isotope Filtering with Bootstrap Tabs – Custom Post Type Query Loop in each Tab (Have to click twice to filter)
  49. Custom post ui plugin & WP_Query – Polylang
  50. changing meta value and meta key of price field
  51. How can I get the number of custom post type posts that have a specific attachment image set?
  52. Posting to a Custom Post Type from front end – user generated content
  53. How to use load more custom post type data normal or according to on click category tab In WP
  54. orderby rand is not working for a custom post types
  55. Update Post Meta for a logged in user
  56. Getting meta in editor plugin, and event triggering issue
  57. Problem querying Custom post type by custom fields
  58. Orderby CPT custom fields not working
  59. Custom taxonomy rewrite give pagination 404
  60. How to duplicate entire custom post type
  61. WP_Query order by custom field, then randomly order some of results
  62. A better way to add a meta box to custom post types
  63. Restrict Access to Posts based on Custom User and Post Meta Data
  64. WP_Query inside foreach loop returning same value for all options when filtered using ajax
  65. Mixing 2 custom post types with posts output in specific pattern
  66. Custom post taxonomies as tax_query terms?
  67. Two Custom Post Types Many to Many Relationship
  68. get_post_meta not working on publishing
  69. Should wp_postmeta meta_key always be unique for a given post_id?
  70. creat filter with wp_query
  71. Troubles with acf/save_post and WP_Query
  72. A method for ordering mixed dates in search result loop (theory only, no actual code)
  73. Query custom post type with ACF Date
  74. How to do WP_Query with two meta fields with orderby clause
  75. Stuck in Order by more then one
  76. Display featured image from one CPT within another CPT query
  77. how can I register a post_meta field in an existing CPT and then call it again with get_post_custom()?
  78. get_post_meta returning no value in custom post type alert email
  79. Custom WP Query on custom meta and sort by multiple meta keys value
  80. Show only one post on custom post type archive
  81. Woocommerce search pagination not working
  82. How to order WP_Query by parent for hierarchical Custom Post Type?
  83. Including metaboxes from custom post types in global search — continued
  84. WordPress loop: Show only a Custom Post Type Taxononmy TERM
  85. post meta parameter in post custom-post-type endpoint with restapi
  86. How can I made custom taxonomies relationship?
  87. How do I set all of a particular post meta to a value within the custom post type I’m in?
  88. Query Multiple Custom Posts by Custom Fields
  89. What’s the WP way to load remaining custom posts?
  90. Why is this query not working? (Standard posts + custom post type)
  91. How do you paginate a query grouped by month?
  92. Custom taxonomies relationship
  93. Get Posts by multiple custom fields is not working
  94. Custom post type ‘articles’ ignores posts_per_page, reserved post_type?
  95. Several post types on WP Query by tag and taxonomy
  96. Update postmeta Parent when post_status child change
  97. WP Query with categories only shows one post and ignores the category
  98. Metabox not show in categories custom post type cmb2
  99. Polylang non-default language ignores tags in WP_Query
  100. Custom Widget WP_Query problem
Categories custom-post-types Tags custom-post-types, post-meta, wp-query
Empty taxonomy items for CPT in admin grid
How do I write a subdomain redirect?

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