我有查询页面的问题。我想查询所有页面,但它不起作用。我做错了什么?我不知道。请帮我。public function my_get_all_page_types() { $page_args = array( 'post_type' => 'page', 'post_status' => 'publish', 'posts_per_page' => -1, ); $pages = $page_args; $page_list = []; foreach ($pages as $page) { $page_list[$page->ID] = $page->post_title; } return $page_list;}这是输出:$this->add_control( 'UA_page_list_select', [ 'label' => __( 'Page List Box', 'my-elementor' ), 'type' => Controls_Manager::SELECT, 'multiple' => false, 'default' => [], 'options' => $this->my_get_all_page_types(), ] );这是我的另一种方式:public function my_get_all_page_types() { $pages = get_pages(); foreach ( $pages as $page ) { $option .= $page->post_title; echo $option; }}
1 回答
慕的地8271018
TA贡献1796条经验 获得超4个赞
您没有将查询参数传递给wp_query对象。只需用以下功能替换您的上述功能 -
public function my_get_all_page_types() {
$page_args = array(
'post_type' => 'page',
'post_status' => 'publish',
'numberposts' => -1,
);
$pages = get_posts($page_args);
$page_list = [];
foreach ($pages as $page) {
$page_list[$page->ID] = $page->post_title;
}
return $page_list;
}
- 1 回答
- 0 关注
- 132 浏览
添加回答
举报
0/150
提交
取消