2011-07-26 13 views
1

パスワードで保護されている投稿を除外するために、以下のコードをどのように変更することができますか?私はwhileステートメント内のifステートメントでこれを行うことができますが、WP_Queryポイントから除外したいと思います。あなたはあなたのクエリを実行する直前に、それはpost_whereフィルタで実現することができますワードプレスのページからパスワードで保護された投稿を除外する

$pq = new WP_Query(array('post_type' => $ptype, 'showposts' => $pshow)); 

答えて

2

function getNonPasswordedPosts(){  
    // Add the filter to exclude passworded posts 
    add_filter('posts_where', 'excludePassworded'); 

    // Query for the posts 
    $pq = new WP_Query(array('post_type' => $ptype, 'showposts' => $pshow)); 

    // Remove the filter so that other WP queries don't exclude passworded posts 
    remove_filter('posts_where', 'excludePassworded'); 

    // iterate over returned posts and do fancy stuff  
} 

function excludePassworded($where) { 
    $where .= " AND post_password = '' "; 
    return $where; 
} 
+0

また、おそらくremove_filter(「posts_where」を使用してクエリの後にフィルタを削除する必要があります「excludePassworded」 ); – HWD

+0

良いお電話@HWD - 私は自分の答えを更新しました。 – Pat

関連する問題