public static function getWhere($args = array(), $load_terms = true)
    {
        $instance = Post\Factory::create(get_called_class());

        // Allow sorting both by core fields and custom fields
        // See: http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
        $default_orderby = $instance->getDefaultOrderBy();
        $default_order = $instance->getDefaultOrder();
        $default_args = array(
            'post_type'  => $instance->getPostType(),
            'numberposts'=> -1,
            'orderby'    => $default_orderby,
            'order'      => $default_order,
        );

        // Sometimes you will specify a default orderby using getDefaultOrderBy
        if ($default_orderby !== 'menu_order') {
            $fields = $instance->getFields();
            if (array_key_exists($default_orderby, $fields)) {
                $default_args['meta_key'] = $default_orderby;
                
                // Number fields should be sorted numerically, not alphabetically
                // Of course, this currently requires you to use type=number to achieve numeric sorting
                $default_args['orderby'] = ($fields[$default_orderby]['type'] === 'number')
                    ? 'meta_value_num'
                    : 'meta_value';
            }
        }

        // But other times, you'll just pass in orderby via $args,
        // e.g. if you call getBy or getWhere with the $args param
        if (array_key_exists('orderby', $args)) {
            $fields = $instance->getFields();
            if (array_key_exists($args['orderby'], $fields)) {
                $args['meta_key'] = $args['orderby'];
                
                // Number fields should be sorted numerically, not alphabetically
                // Of course, this currently requires you to use type=number to achieve numeric sorting
                $args['orderby'] = ($fields[$args['orderby']]['type'] === 'number')
                    ? 'meta_value_num'
                    : 'meta_value';
            }
        }
        
        $criteria = array_merge($default_args, $args);
        return Post\Factory::createMultiple(get_posts($criteria), $load_terms);
    }
public static function getWhere($args = array(), $load_terms = true)
    {
        $instance = Post\Factory::create(get_called_class());

        // Allow sorting both by core fields and custom fields
        // See: http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters
        $default_orderby = $instance->getDefaultOrderBy();
        $default_order = $instance->getDefaultOrder();
        $default_args = array(
            'post_type'  => $instance->getPostType(),
            'numberposts'=> -1,
            'orderby'    => $default_orderby,
            'order'      => $default_order,
        );

        // Sometimes you will specify a default orderby using getDefaultOrderBy
        if ($default_orderby !== 'menu_order') {
            $fields = $instance->getFields();
            if (array_key_exists($default_orderby, $fields)) {
                $default_args['meta_key'] = $default_orderby;
                
                // Number fields should be sorted numerically, not alphabetically
                // Of course, this currently requires you to use type=number to achieve numeric sorting
                $default_args['orderby'] = ($fields[$default_orderby]['type'] === 'number')
                    ? 'meta_value_num'
                    : 'meta_value';
            }
        }

        // But other times, you'll just pass in orderby via $args,
        // e.g. if you call getBy or getWhere with the $args param
        if (array_key_exists('orderby', $args)) {
            $fields = $instance->getFields();
            if (array_key_exists($args['orderby'], $fields)) {
                $args['meta_key'] = $args['orderby'];
                
                // Number fields should be sorted numerically, not alphabetically
                // Of course, this currently requires you to use type=number to achieve numeric sorting
                $args['orderby'] = ($fields[$args['orderby']]['type'] === 'number')
                    ? 'meta_value_num'
                    : 'meta_value';
            }
        }
        
        $criteria = array_merge($default_args, $args);
        return Post\Factory::createMultiple(get_posts($criteria), $load_terms);
    }
public static function getWhere ( $ args = array ( ) , $ load_terms = true ) { $ instance = Post \ Factory :: create ( get_called_class ( ) ) ; // Allow sorting both by core fields and custom fields // See: http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters $ default_orderby = $ instance -> getDefaultOrderBy ( ) ; $ default_order = $ instance -> getDefaultOrder ( ) ; $ default_args = array ( 'post_type' => $ instance -> getPostType ( ) , 'numberposts' => - 1 , 'orderby' => $ default_orderby , 'order' => $ default_order , ) ; // Sometimes you will specify a default orderby using getDefaultOrderBy if ( $ default_orderby !== 'menu_order' ) { $ fields = $ instance -> getFields ( ) ; if ( array_key_exists ( $ default_orderby , $ fields ) ) { $ default_args [ 'meta_key' ] = $ default_orderby ; // Number fields should be sorted numerically, not alphabetically // Of course, this currently requires you to use type=number to achieve numeric sorting $ default_args [ 'orderby' ] = ( $ fields [ $ default_orderby ] [ 'type' ] === 'number' ) ? 'meta_value_num' : 'meta_value' ; } } // But other times, you'll just pass in orderby via $args, // e.g. if you call getBy or getWhere with the $args param if ( array_key_exists ( 'orderby' , $ args ) ) { $ fields = $ instance -> getFields ( ) ; if ( array_key_exists ( $ args [ 'orderby' ] , $ fields ) ) { $ args [ 'meta_key' ] = $ args [ 'orderby' ] ; // Number fields should be sorted numerically, not alphabetically // Of course, this currently requires you to use type=number to achieve numeric sorting $ args [ 'orderby' ] = ( $ fields [ $ args [ 'orderby' ] ] [ 'type' ] === 'number' ) ? 'meta_value_num' : 'meta_value' ; } } $ criteria = array_merge ( $ default_args , $ args ) ; return Post \ Factory :: createMultiple ( get_posts ( $ criteria ) , $ load_terms ) ; }
Get posts with conditions
@param array $args
@param bool $load_terms
@return array
Get posts with conditions