/** * Map gallery parameters to wp_query native parameters * * @param type $args * @return string */ public function build_params($args) { $defaults = array('type' => array_keys(mpp_get_active_types()), 'id' => false, 'in' => false, 'exclude' => false, 'slug' => false, 'status' => array_keys(mpp_get_active_statuses()), 'component' => array_keys(mpp_get_active_components()), 'component_id' => false, 'per_page' => mpp_get_option('galleries_per_page'), 'offset' => false, 'page' => false, 'nopaging' => false, 'order' => 'DESC', 'orderby' => 'date', 'user_id' => false, 'include_users' => false, 'exclude_users' => false, 'user_name' => false, 'scope' => false, 'search_terms' => '', 'year' => false, 'month' => false, 'week' => '', 'day' => '', 'hour' => '', 'minute' => '', 'second' => '', 'yearmonth' => false, 'fields' => false); //build params for WP_Query $r = wp_parse_args($args, $defaults); extract($r, EXTR_SKIP); //build the wp_query args $wp_query_args = array('post_type' => mpp_get_gallery_post_type(), 'post_status' => 'any', 'p' => $id, 'post__in' => $in, 'post__not_in' => $exclude, 'name' => $slug, 'posts_per_page' => $per_page, 'paged' => $page, 'offset' => $offset, 'nopaging' => $nopaging, 'author' => $user_id, 'author_name' => $user_name, 'author__in' => $include_users, 'author__not_in' => $exclude_users, 'year' => $year, 'monthnum' => $month, 'w' => $week, 'day' => $day, 'hour' => $hour, 'minute' => $minute, 'second' => $second, 'm' => $yearmonth, 'order' => $order, 'orderby' => $orderby, 's' => $search_terms, 'fields' => $fields, '_mpp_mapped_query' => true); $tax_query = array(); $gmeta_query = array(); //meta if (isset($meta_key) && $meta_key) { $wp_query_args['meta_key'] = $meta_key; } if (isset($meta_value)) { $wp_query_args['meta_value'] = $meta_value; } if (isset($meta_query)) { $gmeta_query = $meta_query; } //TODO: SCOPE // //we will need to build tax query/meta query //type, audio video etc //if type is given and it is valid gallery type //Pass one or more types //should we restrict to active types only here? I guss no, Insteacd the calling scope should take care of that if (!empty($type) && mpp_are_registered_gallery_types($type)) { $type = mpp_string_to_array($type); $type = array_map('mpp_underscore_it', $type); $tax_query[] = array('taxonomy' => mpp_get_type_taxname(), 'field' => 'slug', 'terms' => $type, 'operator' => 'IN'); } //privacy //pass ne or more privacy level if (!empty($status) && mpp_are_registered_gallery_statuses($status)) { $status = mpp_string_to_array($status); $status = array_map('mpp_underscore_it', $status); $tax_query[] = array('taxonomy' => mpp_get_status_taxname(), 'field' => 'slug', 'terms' => $status, 'operator' => 'IN'); } if (!empty($component) && mpp_are_registered_gallery_components($component)) { $component = mpp_string_to_array($component); $component = array_map('mpp_underscore_it', $component); $tax_query[] = array('taxonomy' => mpp_get_component_taxname(), 'field' => 'slug', 'terms' => $component, 'operator' => 'IN'); } //done with the tax query if (count($tax_query) > 1) { $tax_query['relation'] = 'AND'; } $wp_query_args['tax_query'] = $tax_query; // print_nice($wp_query_args); //meta query //now, for component if (!empty($component_id)) { $meta_compare = '='; if (is_array($component_id)) { $meta_compare = 'IN'; } $gmeta_query[] = array('key' => '_mpp_component_id', 'value' => $component_id, 'compare' => $meta_compare, 'type' => 'UNSIGNED'); } //reset meta query if (!empty($gmeta_query)) { $wp_query_args['meta_query'] = $gmeta_query; } // print_r($wp_query_args); return $wp_query_args; }
public function build_params($args) { $defaults = array('type' => array_keys(mpp_get_active_types()), 'id' => false, 'in' => false, 'exclude' => false, 'slug' => false, 'status' => array_keys(mpp_get_active_statuses()), 'component' => array_keys(mpp_get_active_components()), 'component_id' => false, 'gallery_id' => false, 'galleries' => false, 'galleries_exclude' => false, 'storage' => '', 'per_page' => mpp_get_option('media_per_page'), 'offset' => false, 'page' => false, 'nopaging' => false, 'order' => 'DESC', 'orderby' => false, 'user_id' => false, 'user_name' => false, 'scope' => false, 'search_terms' => '', 'year' => false, 'month' => false, 'week' => '', 'day' => '', 'hour' => '', 'minute' => '', 'second' => '', 'yearmonth' => '', 'meta_query' => false, 'fields' => false); //build params for WP_Query /** * If wer are querying for a single gallery * and the gallery media were sorted by the user, show the media s in the sort order insted of the default date */ if (isset($args['gallery_id']) && mpp_is_gallery_sorted($args['gallery_id'])) { $defaults['orderby'] = 'menu_order'; } $r = wp_parse_args($args, $defaults); extract($r, EXTR_SKIP); //build the wp_query args $wp_query_args = array('post_type' => mpp_get_media_post_type(), 'post_status' => 'any', 'p' => $id, 'post__in' => $in, 'post__not_in' => $exclude, 'name' => $slug, 'post_parent' => $gallery_id, 'post_parent__in' => !empty($galleries) ? (array) $galleries : 0, 'post_parent__not_in' => !empty($galleries_exclude) ? (array) $galleries_exclude : 0, 'posts_per_page' => $per_page, 'paged' => $page, 'offset' => $offset, 'nopaging' => $nopaging, 'author' => $user_id, 'author_name' => $user_name, 'year' => $year, 'monthnum' => $month, 'w' => $week, 'day' => $day, 'hour' => $hour, 'minute' => $minute, 'second' => $second, 'm' => $yearmonth, 'order' => $order, 'orderby' => $orderby, 's' => $search_terms, 'fields' => $fields, '_mpp_mapped_query' => true); //TODO: SCOPE // //we will need to build tax query/meta query //taxonomy query to filter by component|status|privacy $tax_query = array(); //meta query $gmeta_query = array(); if (isset($meta_key) && $meta_key) { $wp_query_args['meta_key'] = $meta_key; } if (isset($meta_key) && $meta_key && isset($meta_value)) { $wp_query_args['meta_value'] = $meta_value; } //if meta query was specified, let us keep it and we will add our conditions if (!empty($meta_query)) { $gmeta_query = $meta_query; } //we will need to build tax query/meta query //type, audio video etc //if type is given and it is valid gallery type //Pass one or more types if (!empty($type) && mpp_are_registered_gallery_types($type)) { $type = mpp_string_to_array($type); //we store the terms with _name such as private becomes _private, members become _members to avoid conflicting terms $type = array_map('mpp_underscore_it', $type); $tax_query[] = array('taxonomy' => mpp_get_type_taxname(), 'field' => 'slug', 'terms' => $type, 'operator' => 'IN'); } //privacy //pass one or more privacy level if (!empty($status) && mpp_are_registered_gallery_statuses($status)) { $status = mpp_string_to_array($status); $status = array_map('mpp_underscore_it', $status); $tax_query[] = array('taxonomy' => mpp_get_status_taxname(), 'field' => 'slug', 'terms' => $status, 'operator' => 'IN'); } if (!empty($component) && mpp_are_registered_gallery_components($component)) { $component = mpp_string_to_array($component); $component = array_map('mpp_underscore_it', $component); $tax_query[] = array('taxonomy' => mpp_get_component_taxname(), 'field' => 'slug', 'terms' => $component, 'operator' => 'IN'); } //done with the tax query if (count($tax_query) > 1) { $tax_query['relation'] = 'AND'; } if (!empty($tax_query)) { $wp_query_args['tax_query'] = $tax_query; } //now, for component if (!empty($component_id)) { $meta_compare = '='; if (is_array($component_id)) { $meta_compare = 'IN'; } $gmeta_query[] = array('key' => '_mpp_component_id', 'value' => $component_id, 'compare' => $meta_compare, 'type' => 'UNSIGNED'); } //also make sure that it only looks for gallery media $gmeta_query[] = array('key' => '_mpp_is_mpp_media', 'value' => 1, 'compare' => '=', 'type' => 'UNSIGNED'); //should we avoid the orphaned media //Let us discuss with the community and get it here if (!mpp_get_option('show_orphaned_media')) { $gmeta_query[] = array('key' => '_mpp_is_orphan', 'compare' => 'NOT EXISTS'); } //Let us filter the media by storage method if (!empty($storage)) { $gmeta_query[] = array('key' => '_mpp_storage_method', 'value' => $storage, 'compare' => '='); } //and what to do when a user searches by the media source(say youtube|vimeo|xyz.. how do we do that?) //reset meta query if (!empty($gmeta_query)) { $wp_query_args['meta_query'] = $gmeta_query; } return $wp_query_args; //http://wordpress.stackexchange.com/questions/53783/cant-sort-get-posts-by-post-mime-type }