Inventory_Presser_Shortcode_Slider::get_vehicle_IDs( $shortcode_atts )
Source Source
File: includes/shortcode/class-shortcode-inventory-slider.php
public static function get_vehicle_IDs( $shortcode_atts ) {
$gpargs = array(
'posts_per_page' => 10,
'post_type' => INVP::POST_TYPE,
'meta_query' => array(
'relation' => 'AND',
array(
'key' => apply_filters( 'invp_prefix_meta_key', 'featured' ),
'value' => 1,
'compare' => '=',
),
array(
'key' => '_thumbnail_id',
'compare' => 'EXISTS',
),
),
'fields' => 'ids',
'orderby' => $shortcode_atts['orderby'],
'order' => $shortcode_atts['order'],
);
$inventory_ids = get_posts( self::add_make_and_model_query_args( $gpargs, $shortcode_atts ) );
// If we found less than 10 vehicles, do not required featured vehicles.
if ( count( $inventory_ids ) < 10 ) {
$gpargs = array(
'posts_per_page' => 10 - ( count( $inventory_ids ) ),
'post_type' => INVP::POST_TYPE,
'meta_query' => array(
'relation' => 'AND',
array(
'relation' => 'OR',
array(
'key' => apply_filters( 'invp_prefix_meta_key', 'featured' ),
'value' => array( '', '0' ),
'compare' => 'IN',
),
array(
'key' => apply_filters( 'invp_prefix_meta_key', 'featured' ),
'compare' => 'NOT EXISTS',
),
),
array(
'key' => '_thumbnail_id',
'compare' => 'EXISTS',
),
),
'fields' => 'ids',
'orderby' => $shortcode_atts['orderby'],
'order' => $shortcode_atts['order'],
);
$inventory_ids += get_posts( self::add_make_and_model_query_args( $gpargs, $shortcode_atts ) );
}
if ( ! $inventory_ids ) {
return array();
}
shuffle( $inventory_ids );
return $inventory_ids;
}
Expand full source codeCollapse full source codeView on Github