There is no ‘magic’ in it, but there are two magic
methods of WP_Post
class, __isset()
, and __get()
.
Your extra_data
is not a property of WP_Post
class, so first var_dump
does not include it.
A reference to non existing property of WP_Post
employs those magic
methods, mentioned above, to retrieve post’s metadata.
First, $post->__isset('extra_data')
will be executed, if false
is returned, then $post->extra_data
will be an empty array, otherwise $post->__get('extra_data')
will run, returning metadata. That’s why your second var_dump
shows extra_data
.
Note: Milo’s first comment to this question is, in fact, the perfect answer.
Related Posts:
- How to update custom fields using the wp_insert_post() function?
- How to display multiple Post meta_key/meta_values by SQL query
- How to use multiple query with same meta key
- How can update custom meta for all posts
- Use ajax to update_post_meta
- how to increase custom post value by one most efficiently?
- How can I create a list of page titles from custom meta values?
- Store multiple custom field as post meta per post(css, js, html, 2 link) [closed]
- How to VAR_DUMP a $variable during checkout process (Is my product meta callable?)
- Is it possible to retrieve all posts with a certain value for metadata?
- Non-Closing PHP Query in WordPress Loop
- how to get serialized post meta
- WordPress loop by meta key that is an array? and how loop multiple arrays
- How to store multiple custom meta box
- Order a WP_Query by meta value where the value is an array
- Add a custom class to the body tag using custom fields
- Define category ID using get_post_meta
- Hide a div when a custom field is empty
- WordPress stripping out custom field tags
- Order category posts by last word of custom field
- Add a “custom field” to a category that can be retrieved when viewing the category page with get_post_meta
- How to update custom fields when post is published?
- WP post meta – for loop inside for loop
- When working with a post, almost all wp_postmeta are deleted
- Updating Lat and Lng of posts automatically gives sporadic results
- If custom field doesn’t exist, or exists and it’s true show title?
- Most efficient way to add javascript file to specific post and/or pages?
- Display all values of custom a field created with ACF on a page
- How to automatically apply woocommerce product title to all product images alt tags?
- If Custom Field is empty don’t display div
- How to update single value in multi dimensional Post Meta?
- Add custom field to attachments in a specific category
- get_post_custom single array
- Make custom field meta not display if there is not data in it
- How to Display Image Meta underneath EVERY image in EVERY post
- Get Current User Id Inside a Loop Returns 0 For a Shortcode
- Passing the custom field values in the wp_get_current_user array function
- Advanced Meta Query for Large Calendar Website (12k+ posts) (175k+ wp_postmeta rows)
- wordpress allow user to edit user profile with custom fields
- Sort custom meta column by other meta value
- auto-populating custom nav with all items from custom post type
- Automatic Shortcode Creation with Custom Fields [closed]
- How would an if statement surrounding a custom field with two variables (holding values) look like?
- How to combine 2 php functions into one function with a custom field
- Saving zero in meta box
- How to check if a PHP string is different than meta field?
- Why does this update_post_meta function not delete the custom field itself?
- Querying Database with wpdb
- Only show image from custom field when present
- Hide Heading if ACF Field is empty
- Custom meta box values are not getting saved for my custom post type
- WP_Query: getting posts where custom field exists
- Creating an image from a custom field
- User Meta Value not echoing despite Var_Dump Showing correct string
- WP All Import / Update stock quantity from multiple XML files
- Add category to post meta
- Concatenate Custom Field Value & HTML Value
- Unable to render custom field after attempt to generate a list of recent post in page template
- Unable to Call More than One Meta Box Output
- Conditional On custom field plugin metabox
- Filter unique custom field value based on custom taxonomy category or other custom field
- Display background color or image with custom meta box?
- Meta boxes only displayed when editing normal (default wp post_type) posts
- Can ‘Custom Field’ data be inserted into this Short Code?
- Using an “IF” statement based on the existence of custom field
- Query pulling a single post per month
- Woocommerce Custom Meta Boxes- How to only display if they actually have content
- Adding a custom meta field with default NULL value which is not selectable
- How do you save the values from custom fields to a products data
- Products listing check if meta checkbox is checked
- Is it possible to update the dataset using update_post_meta
- Hide a div if the fiels is empty
- Inserting a class on before_widget if checkbox is checked
- Delete post meta by serialized meta value
- What is the correct way to search 3 custom fields only in WordPress?
- wp_get_nav_menu_items() with ACF
- Show a text if the post has written by author user role in WordPress
- How do I get the value of a current user’s custom field?
- Reverse Cross-Sells (WooCommerce)
- Get field in readable word
- Remove item from post_meta array via AJAX
- Get meta_query value by user meta array
- Custom fields changes the formatting of metabox input
- Include a custom field in mysql query
- Display Content Based on Custom Field Value
- Postmeta not saving
- How to link a word comprised of a custom field with another?
- Custom field in title
- How can I put a custom field as the link of a button shortcode?
- I want Page titles and excerpts to show up on home.php in certain order
- Posts sortable column not sorting properly for custom field numbers
- ACF Date fileds to Age Convert [closed]
- Save custom field value to variable for conditional – why is this not working? [closed]
- Appending an ACF custom field to the page title
- How do I get a function to work in single.php
- How to initialise WP_Query on the basis of a specific meta_value and continue iterating rest?
- I want to show image from custom field image on my custom page template
- Custom Admin Menu Report for Specific User ID
- How to modify default tags in wp_head()
- ACF number less than comparison not working