Make WordPress Core


Ignore:
Timestamp:
03/04/2014 07:44:28 AM (11 years ago)
Author:
nacin
Message:

Add has_password and post_password query variables to WP_Query.

  • has_password true means posts with passwords, false means posts without.
  • post_password can query for posts with a particular password.

props wonderboymusic, robmiller.
fixes #20308.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/query.php

    r27304 r27395  
    27032703        }
    27042704
     2705        if ( isset( $q['post_password'] ) ) {
     2706            $where .= $wpdb->prepare( " AND $wpdb->posts.post_password = %s", $q['post_password'] );
     2707            if ( empty( $q['perm'] ) ) {
     2708                $q['perm'] = 'readable';
     2709            }
     2710        } elseif ( isset( $q['has_password'] ) ) {
     2711            $where .= sprintf( " AND $wpdb->posts.post_password %s ''", $q['has_password'] ? '!=' : '=' );
     2712        }
     2713
    27052714        if ( 'any' == $post_type ) {
    27062715            $in_search_post_types = get_post_types( array('exclude_from_search' => false) );
Note: See TracChangeset for help on using the changeset viewer.