method_get_post_array()
method_get_post_array( $type, $none = '', $labels = false )
Gets an associative array of post IDs and titles for a given post type.
Description
Queries all published posts of the specified type, ordered alphabetically by title. Returns an associative array suitable for CMB2 select fields or other option lists.
Parameters
$type (string) :
The post type slug (e.g., 'post', 'page', 'guide').
$none (string) :
Optional label for a “none” option at key 0. Pass an empty string to omit.
$labels (bool) :
When true, appends the post type’s singular name in parentheses (e.g., "My Page (Page)"). Default false.
Return
(array) Associative array of post_id => title.
Source
File: lib/helper-functions.php
Usage
PHP
$pages = method_get_post_array( 'page', 'Select a page...' );
// Returns: [ 0 => 'Select a page...', 42 => 'About Us', 15 => 'Contact', ... ]