/** * Return campaigns to display in the campaigns shortcode. * * @param array $args * @return WP_Query * @access public * @static * @since 1.0.0 */ public static function get_campaigns($args) { $query_args = array('posts_per_page' => $args['number']); /* Pagination */ if (!empty($args['paged'])) { $query_args['paged'] = $args['paged']; } /* Set category constraint */ if (!empty($args['category'])) { $query_args['tax_query'] = array(array('taxonomy' => 'campaign_category', 'field' => 'slug', 'terms' => $args['category'])); } /* Set author constraint */ if (!empty($args['creator'])) { $query_args['author'] = $args['creator']; } /* Only include active campaigns if flag is set */ if (!$args['include_inactive']) { $query_args['meta_query'] = array('relation' => 'OR', array('key' => '_campaign_end_date', 'value' => date('Y-m-d H:i:s'), 'compare' => '>=', 'type' => 'datetime'), array('key' => '_campaign_end_date', 'value' => 0, 'compare' => '=')); } if (!empty($args['exclude'])) { $query_args['post__not_in'] = explode(',', $args['exclude']); } /* Return campaigns, ordered by date of creation. */ if ('post_date' == $args['orderby']) { $query_args['orderby'] = 'date'; $query_args['order'] = 'DESC'; return Charitable_Campaigns::query($query_args); } /* Return campaigns, ordered by how much money has been raised. */ if ('popular' == $args['orderby']) { return Charitable_Campaigns::ordered_by_amount($query_args); } /* Return campaigns, ordered by how soon they are ending. */ return Charitable_Campaigns::ordered_by_ending_soon($query_args); }