How to cast custom post type into separate class instead of WP_Post

WP_Post class in WP is final, so it explicitly forbids subclassing. It is also quite vague in practice, a lot of code around will happily take/produce post–like objects as long as they have established data structure.

It is challenging to recommend an alternative without knowing more about your specific needs. In a general and assuming use in templates the typical would be to create a template tag function that will calculate score for review post, provided to it as argument and/or current in the Loop.

Leave a Comment