カスタムフィールドの条件が一つの場合
<?php
$args = array(
'posts_per_page' => -1, // 全件取得
'category' => array( 12,14 ), // カテゴリ
'meta_key' => 'finished', //カスタムフィールドのキー
'meta_value' => 1, //カスタムフィールドの値
);
$my_posts = get_posts($args);
?>
カスタムフィールドの条件が1つで、並び替えもする場合
<?php
//カスタムフィールドの値で並び替え
$args2 = array(
'posts_per_page' => -1, // 全件取得
'category' => array( 12,14 ) , // カテゴリ
'orderby' => 'meta_value',
'meta_key' => 'period_end_day',
'order' => 'ASC',
'meta_query' => array(
'key' => 'finished',
'value' => 1,
'compare' => '!=',
)
);
$my_posts2 = get_posts($args2);
?>
カスタムフィールドの条件が複数の場合
$args3 = array(
'posts_per_page' => -1, // 全件取得
'category' => 10, // プロジェクトカテゴリ
'meta_query' => array(
'relation' => 'OR', //OR または AND
array(
'key' => 'domain_info_limit_domain',
'value' => $alert_limit,
'compare' => '<',
'type' => 'DATE'
),
array(
'key' => 'domain_info2_limit_domain',
'value' => $alert_limit,
'compare' => '<',
'type' => 'DATE'
),
array(
'key' => 'domain_info3_limit_domain',
'value' => $alert_limit,
'compare' => '<',
'type' => 'DATE'
),
array(
'key' => 'domain_info4_limit_domain',
'value' => $alert_limit,
'compare' => '<',
'type' => 'DATE'
),
array(
'key' => 'domain_info5_limit_domain',
'value' => $alert_limit,
'compare' => '<',
'type' => 'DATE'
),
),
);
$my_posts3 = get_posts($args3);