■cocoon-child-master/functions.php に定義 function get_the_category_ids($post_id){ $categories = array(); if ( get_post_type() === 'hogehoge' ) { $categories = get_the_terms($post_id,'hoge_cat'); } else { $categories = get_the_category($post_id); } $category_IDs = array(); $cat_count = 0; foreach($categories as $category): $cat_count += (intval($category->count) - 1); endforeach ; if ($cat_count > 0) { foreach($categories as $category): if ( get_post_type() === 'hogehoge' ) { array_push( $category_IDs, $category->term_id); } else { array_push( $category_IDs, $category->cat_ID); } endforeach ; } return $category_IDs; } function own_search_filter($query) { if (is_singular( 'hogehoge' ) ) { $query->set( 'post_type', array( 'post', 'hogehoge' ) ); } } add_action( 'pre_get_posts','own_search_filter' ); ■実行ダンプ 【cocoon-master/tmp/related-list.php $args】 array 'post_type' => string 'hogehoge' 'post__not_in' => array 0 => int 1560 'posts_per_page' => int 4 'orderby' => string 'rand' 'no_found_rows' => boolean true 'date_query' => array 0 => array 'after' => string '2020-01-25 0:0:0' 'inclusive' => boolean true 'category__in' => array 0 => int 8 【cocoon-master/tmp/related-list.php $query->query_vars】 array (size=65) 'post_type' => array 0 => string 'post' 1 => string 'hogehoge' 'post__not_in' => array 0 => int 1560 'posts_per_page' => int 4 'orderby' => string 'rand' 'no_found_rows' => boolean true 'date_query' => array 0 => array 'after' => string '2020-01-25 0:0:0' 'inclusive' => boolean true 'category__in' => array 0 => int 8 'error' => string '' 'm' => string '' 'p' => int 0 'post_parent' => string '' 'subpost' => string '' 'subpost_id' => string '' 'attachment' => string '' 'attachment_id' => int 0 'name' => string '' 'pagename' => string '' 'page_id' => int 0 'second' => string '' 'minute' => string '' 'hour' => string '' 'day' => int 0 'monthnum' => int 0 'year' => int 0 'w' => int 0 'category_name' => string '' 'tag' => string '' 'cat' => string '' 'tag_id' => string '' 'author' => string '' 'author_name' => string '' 'feed' => string '' 'tb' => string '' 'paged' => int 0 'meta_key' => string '' 'meta_value' => string '' 'preview' => string '' 's' => string '' 'sentence' => string '' 'title' => string '' 'fields' => string '' 'menu_order' => string '' 'embed' => string '' 'category__not_in' => array empty 'category__and' => array empty 'post__in' => array empty 'post_name__in' => array empty 'tag__in' => array empty 'tag__not_in' => array empty 'tag__and' => array empty 'tag_slug__in' => array empty 'tag_slug__and' => array empty 'post_parent__in' => array empty 'post_parent__not_in' => array empty 'author__in' => array empty 'author__not_in' => array empty 'ignore_sticky_posts' => boolean false 'suppress_filters' => boolean false 'cache_results' => boolean true 'update_post_term_cache' => boolean true 'lazy_load_term_meta' => boolean true 'update_post_meta_cache' => boolean true 'nopaging' => boolean false 'comments_per_page' => string '50' 'order' => string '' 【cocoon-master/tmp/related-list.php $query->request】 SELECT ID FROM posts WHERE 1=1 AND ( post_date >= '2020-01-25 00:00:00' ) AND ID NOT IN (1560) AND ( 0 = 1 ) AND post_type IN ('post', 'hogehoge') AND (post_status = 'publish' OR post_author = 1 AND post_status = 'private') GROUP BY ID ORDER BY RAND() LIMIT 0, 4