The WP_Post class offers access to various properties through magic getters:
$page_template
$ancestors
$post_category
$tag_input
In addition, post meta can be retrieved by using $post->meta_key.
We should not allow the usage of these coding approaches:
- Magic properties are discouraged in the PHP community, because IDEs and other code quality tools cannot understand them.
- Since there are reserved keywords, using
$post->meta_key does not always return the meta data.
- Depending on how the post is instantiated, the meta value will be passed through
sanitize_post_field() before being returned.
- Meta will always be pulled with
$single set to true.
All in all there are no benefits here, and only downsides.
The
WP_Postclass offers access to various properties through magic getters:$page_template$ancestors$post_category$tag_inputIn addition, post meta can be retrieved by using
$post->meta_key.We should not allow the usage of these coding approaches:
$post->meta_keydoes not always return the meta data.sanitize_post_field()before being returned.$singleset totrue.All in all there are no benefits here, and only downsides.