public static function getPairs($args = array())
    {
        $called_class = get_called_class();
        $instance = Post\Factory::create($called_class);

        // Optimize the query if no args
        // Unfortunately, WP doesn't provide a clean way to specify which columns to select
        // If WP allowed that, this custom SQL wouldn't be necessary
        if (!Arr::iterable($args)) {
            global $wpdb;
            $sql = sprintf(
                "SELECT
                    p.ID,
                    p.post_title
                FROM $wpdb->posts p
                WHERE p.post_type = '%s'
                AND (p.post_status = 'publish')
                ORDER BY p.post_title ASC",
                $instance->getPostType()
            );
            $results = $wpdb->get_results($sql);
            if (!Arr::iterable($results)) {
                return array();
            }
            
            return array_combine(
                Collection::pluck($results, 'ID'),
                Collection::pluck($results, 'post_title')
            );
        }
        
        // Custom args provided
        $default_args = array(
            'post_type'  => $instance->getPostType(),
            'numberposts'=> -1,
            'order'      => 'ASC',
            'orderby'    => 'title',
        );
        $args = (Arr::iterable($args)) ? $args : $default_args;
        if (!array_key_exists('post_type', $args)) {
            $args['post_type'] = $instance->getPostType();
        }

        $all = get_posts($args);
        if (!Arr::iterable($all)) {
            return array();
        }

        return array_combine(
            Collection::pluck($all, self::ID),
            Collection::pluck($all, 'post_title')
        );
    }
public static function getPairs($args = array())
    {
        $called_class = get_called_class();
        $instance = Post\Factory::create($called_class);

        // Optimize the query if no args
        // Unfortunately, WP doesn't provide a clean way to specify which columns to select
        // If WP allowed that, this custom SQL wouldn't be necessary
        if (!Arr::iterable($args)) {
            global $wpdb;
            $sql = sprintf(
                "SELECT
                    p.ID,
                    p.post_title
                FROM $wpdb->posts p
                WHERE p.post_type = '%s'
                AND (p.post_status = 'publish')
                ORDER BY p.post_title ASC",
                $instance->getPostType()
            );
            $results = $wpdb->get_results($sql);
            if (!Arr::iterable($results)) {
                return array();
            }
            
            return array_combine(
                Collection::pluck($results, 'ID'),
                Collection::pluck($results, 'post_title')
            );
        }
        
        // Custom args provided
        $default_args = array(
            'post_type'  => $instance->getPostType(),
            'numberposts'=> -1,
            'order'      => 'ASC',
            'orderby'    => 'title',
        );
        $args = (Arr::iterable($args)) ? $args : $default_args;
        if (!array_key_exists('post_type', $args)) {
            $args['post_type'] = $instance->getPostType();
        }

        $all = get_posts($args);
        if (!Arr::iterable($all)) {
            return array();
        }

        return array_combine(
            Collection::pluck($all, self::ID),
            Collection::pluck($all, 'post_title')
        );
    }
public static function getPairs ( $ args = array ( ) ) { $ called_class = get_called_class ( ) ; $ instance = Post \ Factory :: create ( $ called_class ) ; // Optimize the query if no args // Unfortunately, WP doesn't provide a clean way to specify which columns to select // If WP allowed that, this custom SQL wouldn't be necessary if ( ! Arr :: iterable ( $ args ) ) { global $ wpdb ; $ sql = sprintf ( "SELECT
                    p.ID,
                    p.post_title
                FROM $wpdb->posts p
                WHERE p.post_type = '%s'
                AND (p.post_status = 'publish')
                ORDER BY p.post_title ASC" , $ instance -> getPostType ( ) ) ; $ results = $ wpdb -> get_results ( $ sql ) ; if ( ! Arr :: iterable ( $ results ) ) { return array ( ) ; } return array_combine ( Collection :: pluck ( $ results , 'ID' ) , Collection :: pluck ( $ results , 'post_title' ) ) ; } // Custom args provided $ default_args = array ( 'post_type' => $ instance -> getPostType ( ) , 'numberposts' => - 1 , 'order' => 'ASC' , 'orderby' => 'title' , ) ; $ args = ( Arr :: iterable ( $ args ) ) ? $ args : $ default_args ; if ( ! array_key_exists ( 'post_type' , $ args ) ) { $ args [ 'post_type' ] = $ instance -> getPostType ( ) ; } $ all = get_posts ( $ args ) ; if ( ! Arr :: iterable ( $ all ) ) { return array ( ) ; } return array_combine ( Collection :: pluck ( $ all , self :: ID ) , Collection :: pluck ( $ all , 'post_title' ) ) ; }
Get the pairs
@param array $args for get_posts()
@return array
Get the pairs