我有无序的目的地,我按以下方式打印:
$destinations = get_posts( array(
'post_type' => 'destination_showcase',
'posts_per_page' => -1,
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => 'destination_state',
'value' => ':"'.$state_id . '";' , // looking for serialized value in quotes
'compare' => 'LIKE'
)
),
) );
我想按字母顺序打印目的地。当我对#destinations数组进行var_dump-ed时,我获得了所有目的地及其参数。我想得到他们的头衔,即" post_title"并按字母顺序打印。我试过这个,但是没有用:
'orderby'=> $destinations->post_title, 'order' => 'ASC',
任何想法如何完成任务?
答案 0 :(得分:2)
试试这个
$destinations = get_posts( array(
'post_type' => 'destination_showcase',
'posts_per_page' => -1,
'post_status' => 'publish',
'orderby' => 'title',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => 'destination_state',
'value' => ':"'.$state_id . '";' , // looking for serialized value in quotes
'compare' => 'LIKE'
)
),
) );
答案 1 :(得分:1)
如果我正确阅读WP Query manua l,这应该有效:
get_posts( array(
'post_type' => 'destination_showcase',
'posts_per_page' => -1,
'post_status' => 'publish',
'meta_query' => array(
array(
'key' => 'destination_state',
'value' => ':"'.$state_id . '";' ,
'compare' => 'LIKE'
)
),
'orderby' => 'title',
'order' => 'ASC',
) );