ACF と一緒に少しのコードが必要になります
チェックボックス フィールド (例: ブランド) を追加し、functions.php ファイルに次のコードを追加します。
function my_acf_load_field( $field )
{
global $post;
$field['choices'] = array();
wp_reset_query();
$query = new WP_Query(array('show_posts' => 100));
foreach($query->posts as $product_id=>$macthed_product){
$choices[$macthed_product->ID] = $macthed_product->post_title;
}
$field['choices'] = array();
if( is_array($choices) )
{
foreach( $choices as $key=>$choice )
{
$field['choices'][$key] = $choice;
}
}
wp_reset_query();
return $field;
}
add_filter('acf/load_field/name=brands', 'my_acf_load_field');
wp クエリ パラメータを使用して投稿をフィルタリングします。
投稿 ID は、タイトルがメタボックスのラベルとして付けられたチェックボックスの値になります。