[wp-trac] [WordPress Trac] #12955: Add get_post filter
WordPress Trac
noreply at wordpress.org
Fri Nov 18 03:11:23 UTC 2016
#12955: Add get_post filter
------------------------------------+-----------------------------
Reporter: JohnLamansky | Owner:
Type: feature request | Status: new
Priority: normal | Milestone: Future Release
Component: Posts, Post Types | Version:
Severity: normal | Resolution:
Keywords: has-patch dev-feedback | Focuses:
------------------------------------+-----------------------------
Comment (by danieliser):
@MikeSchinkel, @jsphpl - That is not entirely true. In the technical
aspect you are correct, but in execution the idea is doable.
Though you cannot extend WP_Post you can build a custom wrapper. Check out
this working example:
https://github.com/danieliser/wp-oop-dev-
modules/blob/master/Model/Post.php
It basically uses WP_Post::instance then mimics it in an extendable way.
Even allows post_type restriction so that an instance of Forum_Topic won't
be initiated for a post or page.
Beyond that we also use a factory class which is a wrapper for WP_Query
and allows returning a custom post object via the Model\Post classes, as
well as adding custom query args to shortcut your own query needs.
This has actually made it so that a lot of our shortcodes can simply pass
any WP_Query arg as a parameter, as well as the custom ones we have
created that map to more complex query args.
Like I said technically its not extending WP_Post, but it does everything
expected if you could extend it via the Model\Post class.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/12955#comment:48>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list