APF_Demo_CustomFieldType_Select2::getPosts PHP Метод

getPosts() публичный статический Метод

Structure of Response Array

It must be an associative array with the element keys of results and pagination. In the results element must be a numerically index array holding an array with the kes of id and text. The pagination element can be optional and shouold be an array holding an element named more which accepts a boolean value. array( 'results' => array( array( 'id' => 223, 'text' => 'Title of 223' ), array( 'id' => 665, 'text' => 'Title of 665' ), array( 'id' => 9355, 'text' => 'Title of 9355' ), ... ), 'pagination' => array( 'more' => true, // (boolean) or false - whether the next paginated item exists or not. ) ) Or the pagination element can be omitted. array( 'results' => array( array( 'id' => 223, 'text' => 'Title of 223' ), array( 'id' => 665, 'text' => 'Title of 665' ), array( 'id' => 9355, 'text' => 'Title of 9355' ), ... ), )
См. также: https://codex.wordpress.org/Class_Reference/WP_Query#Pagination_Parameters
См. также: https://select2.github.io/examples.html#data-ajax
public static getPosts ( $aQueries, $aFieldset ) : array
Результат array
    public static function getPosts($aQueries, $aFieldset)
    {
        $_aArgs = array('post_type' => 'post', 'paged' => $aQueries['page'], 's' => $aQueries['q'], 'posts_per_page' => 30, 'nopaging' => false);
        $_oResults = new WP_Query($_aArgs);
        $_aPostTitles = array();
        foreach ($_oResults->posts as $_iIndex => $_oPost) {
            $_aPostTitles[] = array('id' => $_oPost->ID, 'text' => $_oPost->post_title);
        }
        return array('results' => $_aPostTitles, 'pagination' => array('more' => intval($_oResults->max_num_pages) !== intval($_oResults->get('paged'))));
    }