カスタムフィールドで投稿を並び替える
並び替えるだけなら (tested 3.5.1)
コメントアウトした、メタクエリは、必要ない
< ?php query_posts( array( 'meta_key'=>'custom_day',
'orderby'=> 'meta_value',
'order'=> 'ASC',
"showposts"=>"7",
/* "meta_query"=>
array(
array(
"meta_key"=>"custom_day",
"meta_compare"=>">",
"type" => "DATE",
)
)*/
)
);
?>
< ?php if(have_posts()): while(have_posts()): the_post(); ?>
< ?php the_title(); echo get_the_date('h i s'); ?>
< ?php endwhile; endif; ?>
抽出条件も必要なら (tested 3.5.1)
以下の例は、カスタムフィールドlunch_info_dayを持つ投稿の中から、カスタムフィールドの日付の値順で、(2013/01/01以降の日付の)投稿を表示する
< ?php query_posts( array( 'meta_key'=>'lunch_info_day',
'orderby'=> 'meta_value',
'order'=> 'ASC',
"showposts"=>"7",
"meta_compare"=> ">",
"meta_value"=> '2013/01/01',
"meta_type" => "DATE",
)
);
?>
< ?php if(have_posts()): while(have_posts()): the_post(); ?>
< ?php the_title(); echo get_the_date('h i s'); ?>
< ?php endwhile; endif; ?>
ポイントは、typeの指定、@see
2013 6 20
"type" => "DATE", を "meta_type" => "DATE", に修正