私は受け取った答えが正しいと思いません。 exclude_from_search
はすべて$query = new WP_Query
が結果を返すのを防ぎます。
コアは言う:
... TRUEに設定する 'exclude_from_search' を持つ任意の型除くリビジョンと種類を取得)
これは一般的な問題と重複が整理されフロントエンドの検索結果ページ vsデータベース内の投稿を検索します。
フロントエンドでカスタムクエリを使用してコンテンツを提示するには、exclude_from_search = false
が必要です。別のアプローチを使用して、idでコンテンツを直接取得してください。
の代わりに検索フロントエンドのメカニズムをフィルタリングする必要があります。これは真がタイプ「既知」手動で再構築せずに、検索からポストタイプを除外している。
function entex_fn_remove_post_type_from_search_results($query){
/* check is front end main loop content */
if(is_admin() || !$query->is_main_query()) return;
/* check is search result query */
if($query->is_search()){
$post_type_to_remove = 'staticcontent';
/* get all searchable post types */
$searchable_post_types = get_post_types(array('exclude_from_search' => false));
/* make sure you got the proper results, and that your post type is in the results */
if(is_array($searchable_post_types) && in_array($post_type_to_remove, $searchable_post_types)){
/* remove the post type from the array */
unset($searchable_post_types[ $post_type_to_remove ]);
/* set the query to the remaining searchable post types */
$query->set('post_type', $searchable_post_types);
}
}
}
add_action('pre_get_posts', 'entex_fn_remove_post_type_from_search_results');
と発言$post_type_to_remove = 'staticcontent';
は、他のポストタイプに合わせて変更することができます。ここでイム行方不明の何かが、私はこのようなポストタイプのシナリオ、クエリによって示す内容が、フロントエンドユーザーへの検索/直接アクセスから非表示を防止するための別の方法を見つけるカント場合
コメントしてください。
私の言葉は、とても簡単です! 私はCPT自身を登録しましたので、 'exclude_from_search' => true – igloobob
を追加しましたので、exclude_from_search行を追加すると実際にページに表示されるコンテンツブロックが停止することに気付きました。それは消える。 CPTをページに表示したいが、検索には表示しない。これは可能ですか? – igloobob
うーん..それは奇妙だ、確かにそれをするべきではない。引き数の配列で、 'exclude_from_search' => trueの行の最後にカンマを忘れてしまったのですか?その行をCPT引数から完全に削除した場合、その内容は戻ってきますか? –