0
設定したカスタム投稿タイプを検索するためのクエリを設定しました。私はすべての投稿を表示することができますので、私はそれが私が望むカスタム投稿の種類を検索していることを知っています。しかし、私が把握できないのは、私が探している各カスタムポストタイプから1つのポストだけを返す方法です。カスタム投稿タイプをクエリし、各カスタム投稿タイプから1つの投稿を返します
例:4つのカスタムポストタイプがあります。 CPT1、CPT2、CPT3、CPT4。 CPT1のタイトル、CPT2のポストを1つ、CPT2のタイトルなどCPT1のタイトル、CPT2のタイトルなど
それぞれのカスタムポストタイプをクエリし、それぞれ独自のループを持つようにしてください。しかし、それはそのためのコードのようです。アドバンスドのお手伝いをありがとうございます。
これは私が今持っているコードです:
$mystate = get_state();
// args
$args = array(
'numberposts' => -1,
'post_type' => array('CPT1','CPT2','CPT3','CPT4'),
'meta_key' => 'state_420',
'meta_value' => $mystate,
'order' => 'ASC',
);
/query
$the_query = new WP_Query($args);
?>
<?php
if ($the_query->have_posts()) : ?>
<?php
/* Start the Loop */
while ($the_query->have_posts()) : $the_query->the_post();
/**
* Run the loop for the search to output the results.
* If you want to overload this in a child theme then include a file
* called content-search.php and that will be used instead.
*/
?>
<li style="display: inline-block;"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>, </li>
<?php
endwhile;
the_posts_pagination(array('mid_size' => 2));
else :
get_template_part('template-parts/content', 'none');
endif; ?>
<?php wp_reset_query(); // Restore global post data stomped by the_post(). ?>
を渡す必要があります – bootstrap714