admin管理员组文章数量:1122832
I'm going to get several fields from wp_query result. I know about wp_list_pluck() function, but it accepts only one field paramether. How to get several ones if I'd like to take several parameters from each post found?
[
Object1 (ID, name, tag),
Object2 (ID, name, tag),
Object3 (ID, name, tag),
etc.
]
Thank you for your help afterwards!
My code excerpt is here:
$search_param = get_param('search_param', null, 'text'); // POST param
$term_id = get_term_by('name', "$search_param", 'image_color')->term_id;
$args = array(
'post_type' => 'any',
'post_status' => 'any',
'meta_query' => array(
array(
'key' => 'image_color',
'value' => sprintf( 's:%s:"%s"', strlen($term_id), $term_id ),
'compare' => 'LIKE'
),
),
);
$query = new WP_Query( $args );
$hello = [
'ID' => wp_list_pluck($query->get_posts(), 'ID'),
'post_title' => wp_list_pluck($query->get_posts(), 'post_title')
];
I'm going to get several fields from wp_query result. I know about wp_list_pluck() function, but it accepts only one field paramether. How to get several ones if I'd like to take several parameters from each post found?
[
Object1 (ID, name, tag),
Object2 (ID, name, tag),
Object3 (ID, name, tag),
etc.
]
Thank you for your help afterwards!
My code excerpt is here:
$search_param = get_param('search_param', null, 'text'); // POST param
$term_id = get_term_by('name', "$search_param", 'image_color')->term_id;
$args = array(
'post_type' => 'any',
'post_status' => 'any',
'meta_query' => array(
array(
'key' => 'image_color',
'value' => sprintf( 's:%s:"%s"', strlen($term_id), $term_id ),
'compare' => 'LIKE'
),
),
);
$query = new WP_Query( $args );
$hello = [
'ID' => wp_list_pluck($query->get_posts(), 'ID'),
'post_title' => wp_list_pluck($query->get_posts(), 'post_title')
];
Share
Improve this question
edited Jan 4, 2015 at 20:06
Павел Иванов
asked Jan 4, 2015 at 20:01
Павел ИвановПавел Иванов
1111 silver badge6 bronze badges
1 Answer
Reset to default 0Try to set 3-rd parametr for wp_list_pluck function, as i see if it's not set then there's happaning an unnessesery, for you, loop. Try to set it to true or some, not existing in Object, key.
Hope it helps.
本文标签: wp queryHow to get several fields from wpquery
版权声明:本文标题:wp query - How to get several fields from wp_query? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736285442a1927460.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论