Changes between Version 2 and Version 3 of Ticket #37255, comment 51
- Timestamp:
- 03/15/2023 09:32:52 PM (3 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #37255, comment 51
v2 v3 1 Actually thinking more about it, perhaps it is not a good idea to promote use of the global `$post` as it might be polluted by third-parties. Think that was a pretty bad problem some years ago. The solution )if I remember corectly) was to do `$post = get_post( $post )` regardless of whether `$post` was int or object. There are over a hundred places in core that do this.1 Actually thinking more about it, perhaps it is not a good idea to promote use of the global `$post` as it might be polluted by third-parties. Think that was a pretty bad problem some years ago. The solution (if I remember correctly) was to do `$post = get_post( $post )` regardless of whether `$post` was int or object. There are over a hundred places in core that do this. 2 2 3 3 Using `get_post()` is the preferred method even if the global `$post` is passed as a param. `get_post()` retrieves the `WP_Post` object from cache or fetches it from the DB if needed. Hence it always works and is "guaranteed".