WordPressで「register_post_type」で作ったあるカスタム投稿タイプをサイト内の検索結果に表示させたくないことがあって、そんな時は「exclude_from_search」を引数の配列に設定してあげるとOKです。
- ‘exclude_from_search’ => true 検索結果に表示させない
- ‘exclude_from_search’ => false 検索結果に表示する
「true」と「false」で上記の意味になります。
使い方例
「spot」というカスタム投稿タイプを検索結果に表示させたくない場合、下のように「exclude_from_search」を使います。
<?php
add_action( 'init', 'add_custompost' );
function add_custompost() {
register_post_type( 'spot',
array(
'exclude_from_search' => true, //ここです。「true」にして検索結果に表示しない
'public' => true,
'has_archive' => true,
'supports' => array('thumbnail','custom-fields','title','editor','revisions'),
'label' => 'スポット'
)
);
}
?>
このページを共有する