Opened 13 years ago
Closed 11 years ago
#20308 closed enhancement (fixed)
Filtering of password protected posts
Reported by: | paddelboot | Owned by: | nacin |
---|---|---|---|
Milestone: | 3.9 | Priority: | normal |
Severity: | normal | Version: | 3.4 |
Component: | Query | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
Goal:
to query for password protected posts only or to remove all password protected posts from a query.
Current solution:
Modify the query SQL by using the 'posts_where' filter as suggested here: http://stackoverflow.com/questions/7538959/how-to-exclude-password-protected-posts-in-wordpress-loop
Suggested solution:
Make it possible to modify a parameter via 'pre_get_posts' or 'request' - filter, i.e. $query->set( 'post_password', TRUE ).
Attachments (3)
Change History (19)
#1
@
13 years ago
- Cc frank@… added
- Keywords changed from password, pre_get_posts, query, request, posts_where to password pre_get_posts, query, request, posts_where
- Version changed from 3.3.1 to 3.4
#2
@
13 years ago
- Component changed from General to Query
- Keywords needs-patch added; password pre_get_posts query request posts_where removed
- Type changed from feature request to enhancement
#4
@
12 years ago
I could go for post_password as a query variable with these possible values:
- null (ignore)
- false (only posts without passwords)
- true (only posts with passwords)
- a string (posts with this exact password)
In practice, this kind of type-checking is not particularly feasible in WP_Query, unfortunately. Would have to be two different query vars, such as password_exists and post_password. So for now, something like password_exists or has_password seems like a good approach.
#6
@
12 years ago
- Cc r@… added
- Keywords has-patch added; needs-patch removed
I've added a patch that allows querying for password-protected posts in WP_Query.
It adds a query var called "has_password"; if it's truthy, password-protected posts will be returned; if it's falsey, public posts will be returned.
#9
@
11 years ago
- Milestone changed from Awaiting Review to 3.7
Modified the patch to do all of the things @nacin said
#10
@
11 years ago
WP_Query + query variables are not really designed for type-checking, so I'm not sure about 20308.diff. Let's consider has_password => true|false|null. And then we could also do post_password = string to actually check the field's value. Thoughts?
#11
@
11 years ago
- Milestone changed from 3.7 to Future Release
Seems like this could use an alternate approach, so punting.
#12
@
11 years ago
- Keywords dev-feedback removed
- Milestone changed from Future Release to 3.9
20308.2.diff supports has_password => true|false|null
and allows post_password
to be passed explicitly, adding perm => 'readable'
if perm
is not already set.
Adds Unit Tests.
See http://codex.wordpress.org/Reporting_Bugs#Trac_Keywords for allowed keywords.