SO网友:Ignat B.
1) 您需要以以下方式将Posteta包含到用于存档页面的查询中:
add_filter(\'getarchives_join\', \'my_archives_join_filter\');
function my_archives_join_filter($join) {
if (!is_user_logged_in()) {
global $wpdb;
return $join . "LEFT JOIN $wpdb->postmeta ON ($wpdb->posts.ID = $wpdb->postmeta.post_id)";
}
return $join;
}
2)您需要通过以下方式包括条件以选择具有特定元字段的帖子:
add_filter(\'getarchives_where\', \'my_archives_where_filter\');
function my_archives_where_filter($where_clause) {
if (!is_user_logged_in()) {
global $wpdb;
$where_clause = "WHERE $wpdb->posts.post_type = \'post\' AND $wpdb->posts.post_status = \'publish\'";
return $where_clause . "AND $wpdb->posts.meta_key = \'private_page\' AND $wpdb->posts.meta_value = \'0\'";
}
return $where_clause;
}
未针对特定案例进行测试的代码。但总体而言,方法应该是明确的。
更新:好奇到足以测试一种方法的地方。所有工程;)