#34010 closed enhancement (fixed)
Add Ability to Fetch Post Types by Supports
Reported by: | wpsmith | Owned by: | swissspidy |
---|---|---|---|
Milestone: | 4.5 | Priority: | normal |
Severity: | normal | Version: | 4.4 |
Component: | Posts, Post Types | Keywords: | has-patch has-unit-tests commit |
Focuses: | Cc: |
Description
I would be great to see a WordPress function or functions to fetch a list of registered post types that support a specific feature or a set of features.
Attachments (8)
Change History (24)
#2
@
9 years ago
- Keywords 2nd-opinion needs-testing removed
It's not uncommon to loop through to all post types to see if a post type supports a given feature, so this is certainly of value in my opinion. I don't think it's necessary to query by multiple features though.
34010.diff proposes a simple function get_post_types_by_support( $feature )
function (get_post_types_supporting
sounds good too). Basically like in this gist, but without needing to access the global variable.
#3
@
9 years ago
@swissspidy Why are you looping through $post_types
in stead of using the $_wp_post_type_features
global? I see all other post_type_support
related functions are using it.
#4
@
9 years ago
- Keywords has-unit-tests added; dev-feedback needs-unit-tests removed
- Milestone changed from Awaiting Review to 4.5
@barryceelen I don't know anymore, probably just to not rely on the global :)
I don't think it's necessary to query by multiple features though.
Since it's so simple and there are situations where this can indeed be necessary, I changed my mind here. I just uploaded 34010.2.diff now which includes unit tests.
#5
follow-up:
↓ 6
@
9 years ago
:)
While we're at it might as well also add the $operator
parameter like get_post_types()
does (One of the patches by @wpsmith had it but the server is unreachable at the time).
#6
in reply to:
↑ 5
@
9 years ago
Replying to barryceelen:
:)
While we're at it might as well also add the$operator
parameter likeget_post_types()
does (One of the patches by @wpsmith had it but the server is unreachable at the time).
Why don't we just allow passing a 'supports' filter to get_post_types()? Makes more sense IMHO.
#7
@
9 years ago
In fact, the get_post_types() function is where I started looking for this functionality, kinda makes sense to me. Something held me back from modifying that function but I can't recall why :)
#8
@
9 years ago
- Focuses administration template removed
- Keywords needs-refresh added
Adding this to get_post_types()
seems to make more sense, but it would also make the function more complicated.
Let's stick with 34010.2.diff with the operator
argument suggested in 34010.with-operator.diff.
#9
@
9 years ago
Thanks for getting back to this. Adapting the get_post_types()
function indeed got unwieldy when trying to combine/diff the two different $_wp_post_type_features
and $wp_post_types
arrays. Also, the $_wp_post_type_features
array contains 'meta' post types like attachment.video and attachment.audio, unsure how those would be handled.
This ticket was mentioned in Slack in #core by chriscct7. View the logs.
9 years ago
#12
@
9 years ago
- Keywords needs-refresh 2nd-opinion removed
34010.3.diff is an updated patch based on my last comment.
#13
@
9 years ago
- Keywords commit added
- Owner set to swissspidy
- Status changed from new to assigned
Patch looks good.
#14
@
9 years ago
34010.4.diff uses assertContains
instead of assertEqualSets
because some other tests register some random post types, causing these tests to fail.
get_post_types_by_support()