Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I added a post and made it password protected. The post does not show up in a category list I placed on the Courses page, nor does it show up in the search unless you go directly to the page and then login. It then starts appearing on the Courses page. Any idea how to have the link to the post visible? The page they should show up are on: http://www.andrewruis.com/course/. If you search for "asb 129" nothing shows up in the search.

share|improve this question

1 Answer 1

up vote 0 down vote accepted

If a post password is applied and the user is not logged in, the post will not show up in search results. This is the expected behavior of WP_Query:

// If a search pattern is specified, load the posts that match
if ( !empty($q['s']) ) {
    // added slashes screw with quote grouping when done early, so done later
    $q['s'] = stripslashes($q['s']);
    if ( !empty($q['sentence']) ) {
        $q['search_terms'] = array($q['s']);
    } else {
        preg_match_all('/".*?("|$)|((?<=[\r\n\t ",+])|^)[^\r\n\t ",+]+/', $q['s'], $matches);
        $q['search_terms'] = array_map('_search_terms_tidy', $matches[0]);
    }
    $n = !empty($q['exact']) ? '' : '%';
    $searchand = '';
    foreach( (array) $q['search_terms'] as $term ) {
        $term = esc_sql( like_escape( $term ) );
        $search .= "{$searchand}(($wpdb->posts.post_title LIKE '{$n}{$term}{$n}') OR ($wpdb->posts.post_content LIKE '{$n}{$term}{$n}'))";
        $searchand = ' AND ';
    }

    if ( !empty($search) ) {
        $search = " AND ({$search}) ";
        if ( !is_user_logged_in() )
            $search .= " AND ($wpdb->posts.post_password = '') ";
    }
}

See the bottom part? if ( !empty($search) ) { checks to see if we're queuing up a search and, if the user isn't logged in, explicitly searches only for posts that have no password set.

If you need to password protect content anyway, I recommend one of two routes:

1 Require an account

You can easily require users to log in before viewing content - either password-protected or private posts. This gives you complete control over who can see content.

2 Build your own widget

You're trying to include a link to this password-protected content in a dynamic widget. Either use a static list instead (hand-edit the text to include the link) or build your own dynamic widget that does include password-protected posts.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.