我有查询页面的问题。我想查询所有页面,但它不起作用。我做错了什么?我不知道。请帮我。
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;
}
}
慕的地8271018