WordPressでカスタムフィールドの値によって投稿を絞り込む方法のメモです。 カスタムフィールドが特定の値の投稿を取得する カスタムフィールドが特定の値の投稿を取得する方法です。 例として、投稿タイプ『test』で『city』というカスタムフィールドの値が『神戸』という投稿を絞り込んで取得します。 投稿タイプ(post_type):test カスタムフィールドキー(meta_key):city カスタムフィールド値(meta_value):神戸 $args = Array( 'post_type' => 'test', 'posts_per_page' => -1, 'meta_key' => 'city', 'meta_value' => '神戸' ); $the_query = new WP_Query($args); if($the_query -> have_posts()):
![[WordPress] カスタムフィールドで絞り込んで一覧表示する | IT女子のお気に入りフォルダ](https://cdn-ak-scissors.b.st-hatena.com/image/square/8c78905fca2f779277a942d0bbbd6684360ce582/height=288;version=1;width=512/https%3A%2F%2Fsachips.byeto.jp%2Fwp%2Fwp-content%2Fuploads%2F2014%2F11%2Fmafin.jpg)