[wp-trac] [WordPress Trac] #42699: WP_Post $post object not properly returning values for meta keys

WordPress Trac noreply at wordpress.org
Sun Nov 26 02:40:06 UTC 2017

#42699: WP_Post $post object not properly returning values for meta keys
 Reporter:  saiu                |       Owner:
     Type:  defect (bug)        |      Status:  new
 Priority:  normal              |   Milestone:  Awaiting Review
Component:  Options, Meta APIs  |     Version:  4.9
 Severity:  normal              |  Resolution:
 Keywords:                      |     Focuses:

Comment (by saiu):


 I first checked the type of the `$post` variable right where I was trying
 to retrieve the meta key-value. For those where the code wasn't working it
 was an `array`. I added a type check higher up, and for ''each one'' it is
 reporting `$post` is an `object`. The two that worked all along never met
 the `if` condition and never included the `get_template_part`. In that
 template, I had another loop based off a different query to get posts from
 that site of the network. I thought that in a `foreach` loop the `($posts
 as $post)` use of `$post` would be local and not overwrite the broader
 `$post` variable. I changed the variable name in that subloop and all is

 I thought I had searched everywhere in my code and online, found nothing
 obvious, and so posted here thinking I must have hit on some kind of bug.
 Turns out that wasn't the case, so I apologize for mis-filing. Thank you,
 though, for helping me troubleshoot.

Ticket URL: <https://core.trac.wordpress.org/ticket/42699#comment:9>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform

More information about the wp-trac mailing list