如何获取自定义 WP_query 对象
How can I fetch a custom WP_query object
创建新的 WP_query 后,我收到一个结果,但无法理解如何从 "posts" 元素(ID、post_title 等)获取数据:
$bo_query = new WP_query(
array(
'post_type' => 'condominium',
'post_per_page' => -1
)
);
==================================
object(WP_Query)#296 (49) {
["query"]=>
array(2) {...}
["query_vars"]=>
array(65) {...}
["tax_query"]=>
object(WP_Tax_Query)#294 (6) {...}
["meta_query"]=>
object(WP_Meta_Query)#291 (9) {...}
...
["posts"]=>
array(1) {
[0]=>
object(WP_Post)#278 (24) {
["ID"]=>
int(3)
["post_author"]=>
string(1) "1"
...
["post_title"]=>
string(27) "Кайзер Комфорт"
["post_excerpt"]=>
string(0) ""
...
["post_name"]=>
string(13) "kizer-comfort"
}
}
...
}
我需要做什么才能从 ["posts"] 对象获取 ["post_title"]、["post_name"] 等?
对帖子使用 while 循环。请参阅 WP_Query
中的示例
while($bo_query->have_posts()):
$bo_query->the_post();
echo get_the_ID();
the_title();
endwhile;
创建新的 WP_query 后,我收到一个结果,但无法理解如何从 "posts" 元素(ID、post_title 等)获取数据:
$bo_query = new WP_query(
array(
'post_type' => 'condominium',
'post_per_page' => -1
)
);
==================================
object(WP_Query)#296 (49) {
["query"]=>
array(2) {...}
["query_vars"]=>
array(65) {...}
["tax_query"]=>
object(WP_Tax_Query)#294 (6) {...}
["meta_query"]=>
object(WP_Meta_Query)#291 (9) {...}
...
["posts"]=>
array(1) {
[0]=>
object(WP_Post)#278 (24) {
["ID"]=>
int(3)
["post_author"]=>
string(1) "1"
...
["post_title"]=>
string(27) "Кайзер Комфорт"
["post_excerpt"]=>
string(0) ""
...
["post_name"]=>
string(13) "kizer-comfort"
}
}
...
}
我需要做什么才能从 ["posts"] 对象获取 ["post_title"]、["post_name"] 等?
对帖子使用 while 循环。请参阅 WP_Query
中的示例while($bo_query->have_posts()):
$bo_query->the_post();
echo get_the_ID();
the_title();
endwhile;