/** * JobRoller Application Process * Processes a job application sent via the form in a post. * * * @version 1.0 * @author AppThemes * @package JobRoller * @copyright 2010 all rights reserved * */ function jr_process_filter_form() { global $wp_query, $featured_job_cat_id, $find_posts_in, $search_result_ids; if (get_query_var('paged')) { $paged = get_query_var('paged'); } elseif (get_query_var('page')) { $paged = get_query_var('page'); } else { $paged = 1; } $args = array('post_type' => 'job_listing', 'post_status' => 'publish', 'paged' => $paged); $cats = array(); $filter_args = array(); if (isset($_GET['action']) && $_GET['action'] == 'Filter') { $job_types = get_terms('job_type', array('hide_empty' => '0')); if ($job_types && sizeof($job_types) > 0) { foreach ($job_types as $type) { if (isset($_GET[$type->slug])) { // Filter is ON $cats[] = $type->term_id; } } } if (sizeof($cats) == 0) { $cats = array(0); } // Annoyingly, wordpress won't let you query multiple terms from a custom taxonomy - we have to do this the hard way until support is added $post_ids = array(); // *sigh* get posts in each type... foreach ($cats as $cat) { $ids = get_objects_in_term($cat, 'job_type'); $post_ids = array_merge($post_ids, $ids); } // Only unique ones needed $post_ids = array_unique($post_ids); // If we are doing location search, find common ids if (isset($find_posts_in) && is_array($find_posts_in)) { $post_ids = array_intersect($post_ids, $find_posts_in); } if (isset($search_result_ids) && is_array($search_result_ids)) { $post_ids = array_intersect($post_ids, $search_result_ids); } $post_ids[] = 0; // Merge with query args $filter_args = array('post__in' => $post_ids); $args = array_merge($filter_args, $args); } elseif (isset($find_posts_in) && is_array($find_posts_in)) { if (isset($search_result_ids) && is_array($search_result_ids)) { $find_posts_in = array_intersect($find_posts_in, $search_result_ids); } $find_posts_in[] = 0; $filter_args = array('post__in' => $find_posts_in); $args = array_merge($filter_args, $args); } elseif (isset($search_result_ids) && is_array($search_result_ids)) { $filter_args = array('post__in' => $search_result_ids); $args = array_merge($filter_args, $args); } //$args = array_merge($wp_query->query, $args); return $args; }
/** * Get all product ids in a category (and its children) * * @param int $category_id * @return array */ public function get_products_in_category($category_id) { $term_ids = get_term_children($category_id, 'product_cat'); $term_ids[] = $category_id; $product_ids = get_objects_in_term($term_ids, 'product_cat'); return array_unique(apply_filters('woocommerce_report_sales_by_category_get_products_in_category', $product_ids, $category_id)); }
/** * Get letters with posts associated * * @access public * @return void * @author Nicolas Juen */ function get_letters_in_snap() { global $wpdb; $post_in = ''; //If we have the right slug in url if( get_query_var( SNAP_CAT_GLOSSARY ) ){ //Get the id of the current term $termId = get_term_by( 'slug', get_query_var( SNAP_CAT_GLOSSARY ), SNAP_CAT_GLOSSARY )->term_id; //If the term exists we get the related posts if( !empty( $termId ) || !is_wp_error( $termId ) ){ //Get related posts $posts_id = get_objects_in_term( $termId, SNAP_CAT_GLOSSARY ); //Build the additionnal query if we have relatd posts if( !empty( $posts_id ) && !is_wp_error( $posts_id ) ){ $post_in = ' AND p.ID IN ('; $post_in .= implode(',',$posts_id ); $post_in .= ' )'; } } } //Make the query and return it return $wpdb->get_col( $wpdb->prepare("SELECT DISTINCT(LEFT(p.post_title, 1)) FROM $wpdb->posts AS p WHERE p.post_type = '".SNAP_POSTTYPE."' AND p.post_status = 'publish'".$post_in) ); }
function mf_sponsor_list($category_name, $slug = '') { //get the list of links based on faire name $sponsors = get_bookmarks(array('orderby' => 'name', 'category_name' => $category_name, 'limit' => 40)); $slugData = get_term_by('slug', $slug, 'link_category', OBJECT); if (is_object($slugData)) { $slugCat = get_objects_in_term($slugData->term_id, 'link_category'); } else { $slugCat = array(); } //get the list of links based on sponsor category name $slugData = get_term_by('slug', $category_name, 'link_category', OBJECT); $sponsorName = get_objects_in_term($slugData->term_id, 'link_category'); //find the links that are in both the sponsor category and specified faire if (!empty($slugCat)) { $category = array_intersect($slugCat, $sponsorName); } else { $category = $sponsorName; } $include = implode(',', $category); $sponsors = array(); if (!empty($include)) { $sponsors = get_bookmarks(array('orderby' => 'name', 'limit' => 40, 'include' => $include)); } // Get the output started. $output = '<ul>'; // Loop through each block of sponsors foreach ($sponsors as $idx => $spon) { //foreach ($sponsor as $spon) { $output .= '<li><a href="' . esc_url($spon->link_url) . '"><img src="' . legacy_get_resized_remote_image_url($spon->link_image, 125, 105) . '" alt=""></a></li>'; //} } $output .= '</ul>'; return $output; }
function multiple_tax_fix($wp_query) { global $wp_taxonomies; $query = array(); foreach ($wp_taxonomies as $taxonomy => $t) { if ($t->query_var) { if ($var = $wp_query->get($t->query_var)) { $query[$taxonomy] = $var; } } } if (count($query) <= 1) { return; } $ids = array(); foreach ($query as $tax => $term_slug) { if (!($term = get_term_by('slug', $term_slug, $tax))) { return $wp_query->set_404(); } $posts = get_objects_in_term($term->term_id, $tax); if (empty($posts)) { return $wp_query->set_404(); } $ids[] = $posts; } $ids = call_user_func_array('array_intersect', $ids); if (empty($ids)) { $wp_query->set_404(); } $wp_query->set('post__in', $ids); }
function wcapf_get_term_objects($term_id, $taxonomy) { global $wcapf; $unfiltered_product_ids = $wcapf->unfilteredProductIds(); $transient_name = 'wcapf_term_objects_' . md5(sanitize_key($taxonomy) . sanitize_key($term_id)); if (false === ($objects_in_term = get_transient($transient_name))) { $objects_in_term = get_objects_in_term($term_id, $taxonomy); $objects_in_term = array_intersect($objects_in_term, $unfiltered_product_ids); set_transient($transient_name, $objects_in_term, WCAPF_CACHE_TIME); } return (array) $objects_in_term; }
function get_posts_related_by_taxonomy($post_id, $taxonomy, $notin, $args = array()) { $query = new WP_Query(); $terms = wp_get_object_terms($post_id, $taxonomy); if (count($terms)) { // Assumes only one term for per post in this taxonomy $post_ids = get_objects_in_term($terms[0]->term_id, $taxonomy); $post = get_post($post_id); $args = wp_parse_args($args, array('post_type' => $post->post_type, 'post__not_in' => array($notin), 'taxonomy' => $taxonomy, 'term' => $terms[0]->slug, 'posts_per_page' => get_option('tz_related_portfolio_number'))); $query = new WP_Query($args); } return $query; }
/** * Convert items in the social menu to icons in the Fontello icon font */ function fontello_conversion($title, $id = null) { if (has_nav_menu('social_links')) { if (in_array($id, get_objects_in_term(wp_get_nav_menu_object(get_nav_menu_locations()['social_links'])->term_id, 'nav_menu'))) { switch (strtolower($title)) { case "facebook": case "fb": return "f"; break; case "flickr": case "flicker": return "F"; break; case "google+": case "g": case "g+": case "googleplus": case "google plus": return "G"; break; case "instagram": return "i"; break; case "linked in": case "linkedin": case "li": return "L"; break; case "twitter": return "T"; break; case "vimeo": return "v"; break; case "vine": return "V"; break; case "yelp": return "Y"; break; case "youtube": return "y"; break; default: return strtolower($title[0]); } } } return $title; }
/** * Product type meta box * * Display the product type meta box which contains a hook for product types to hook into and show their options * * @since 1.0 */ function jigoshop_product_type_options_box() { global $post; ?> <div id="simple_product_options" class="panel jigoshop_options_panel"> <?php // List Grouped products $posts_in = (array) get_objects_in_term( get_term_by( 'slug', 'grouped', 'product_type' )->term_id, 'product_type' ); $posts_in = array_unique($posts_in); $field = array( 'id' => 'parent_id', 'label' => __('Parent post', 'jigoshop') ); echo '<p class="form-field"><label for="'.$field['id'].'">'.$field['label'].'</label><select id="'.$field['id'].'" name="'.$field['id'].'"><option value="">'.__('Choose a grouped product…', 'jigoshop').'</option>'; if (sizeof($posts_in)>0) : $args = array( 'post_type' => 'product', 'post_status' => 'publish', 'numberposts' => -1, 'orderby' => 'title', 'order' => 'asc', 'post_parent' => 0, 'include' => $posts_in, ); $grouped_products = get_posts($args); $loop = 0; if ($grouped_products) : foreach ($grouped_products as $product) : if ($product->ID==$post->ID) continue; echo '<option value="'.$product->ID.'" '; if ($post->post_parent==$product->ID) echo 'selected="selected"'; echo '>'.$product->post_title.'</option>'; endforeach; endif; endif; echo '</select></p>'; // Ordering $menu_order = $post->menu_order; $field = array( 'id' => 'menu_order', 'label' => _x('Order', 'ordering', 'jigoshop') ); echo '<p class="form-field"> <label for="'.$field['id'].'">'.$field['label'].':</label> <input type="text" class="short" name="'.$field['id'].'" id="'.$field['id'].'" value="'.$menu_order.'" /></p>'; ?> </div> <?php do_action('jigoshop_product_type_options_box'); }
function get_posts_related_by_taxonomy($taxonomy, $posts_per_page, $args = array()) { global $post; $post_id = $post->ID; $query = new WP_Query(); $terms = wp_get_object_terms($post_id, $taxonomy); if (count($terms)) { // Assumes only one term for per post in this taxonomy $post_ids = get_objects_in_term($terms[0]->term_id, $taxonomy); $post = get_post($post_id); $args = wp_parse_args($args, array('post_type' => $post->post_type, 'post__not_in' => array($post_id), 'taxonomy' => $taxonomy, 'term' => $terms[0]->slug, 'exclude' => $post, 'posts_per_page' => $posts_per_page)); $query = new WP_Query($args); } return $query; }
function get_posts_related_by_taxonomy($post_id, $taxonomy, $args = array()) { $terms = wp_get_object_terms($post_id, $taxonomy); $query = new WP_Query(); if (count($terms)) { // Assumes only one term for per post in this taxonomy $post_ids = get_objects_in_term($terms[0]->term_id, $taxonomy); $post = get_post($post_id); $post_id_array = array($post_id); $post_ids_excl = array_diff($post_ids, $post_id_array); $args = wp_parse_args($args, array('post_type' => $post->post_type, 'post__in' => $post_ids_excl, 'taxonomy' => $taxonomy, 'term' => $terms[0]->slug, 'showposts' => 3, 'no_found_rows' => true)); $query = new WP_Query($args); } return $query; }
function handle_duplicate() { if (isset($_REQUEST['_td_nonce']) && check_admin_referer('duplicate_term', '_td_nonce')) { $term_id = $_REQUEST['term_duplicator_term']; $term_tax = $_REQUEST['taxonomy']; $existing_taxonomy_term = get_term($term_id, $term_tax); $new_term = wp_insert_term("{$existing_taxonomy_term->name} Copy", $term_tax, array('description' => $existing_taxonomy_term->description, 'slug' => "{$existing_taxonomy_term->slug}-copy", 'parent' => $existing_taxonomy_term->parent)); if (!is_wp_error($new_term)) { // add all existing posts to new term $posts = get_objects_in_term($term_id, $term_tax); if (!is_wp_error($posts)) { foreach ($posts as $post_id) { $result = wp_set_post_terms($post_id, $new_term['term_id'], $term_tax, true); } } } } }
function go_gold_store_sc($atts, $content = null) { $args = array('post_type' => 'go_store', 'posts_per_page' => 10); // Defines args used to get custom post type content $loop = new WP_Query($args); // Loops in custom post type content if (count(array_keys($loop->posts)) > 0) { $output_array = array(); extract(shortcode_atts(array('cats' => '', 'id' => ''), $atts)); if ($cats) { // the idea is that teachers/educators can leave an optional space between the items in their store. // e.g. [go_store cats='time, music, bathroom-passes'] or [go_store cats='time,music,bathroom-passes'] $cat_array_raw = explode(", ", $cats); // remove comma-space blocks and create an array $cat_string = implode(",", $cat_array_raw); // join the array into a string with commas $cat_array = explode(",", $cat_string); // remove comma blocks and break the string into an array for ($i = 0; $i < count($cat_array); $i++) { $the_term_id = get_term_by('name', $cat_array[$i], 'store_types')->term_id; $the_args = array('orderby' => 'name'); $the_items = get_objects_in_term($the_term_id, 'store_types', $the_args); $upp_cat = ucwords($cat_array[$i]); array_push($output_array, "<h3>" . $upp_cat . "</h3>"); for ($x = 0; $x < count($the_items); $x++) { $the_title = get_the_title($the_items[$x]); array_push($output_array, "<a class='go_str_item' onclick='go_lb_opener(" . $the_items[$x] . ");'>" . $the_title . "</a><br/>"); } } $output_array = implode(" ", $output_array); return $output_array; } else { if ($id) { $the_title = get_the_title($id); // get item title $custom_fields = get_post_custom($id); $req_currency = $custom_fields['go_mta_store_currency'][0]; return '<a class="go_str_item" onclick="go_lb_opener(' . $id . ');">' . $the_title . '</a>'; } } } }
function max_query_term_posts($showposts = PER_PAGE_DEFAULT, $id_array, $type = 'gallery', $random = false, $taxonomy = GALLERY_TAXONOMY, $sorting = false, $filter_current = false) { global $post, $max_random_posts_query; $rand = !$random ? "" : $random; $sort = !$sorting ? "" : $sorting; $posts_to_query = get_objects_in_term($id_array, $taxonomy); if ($filter_current === true) { $_array_diff = array(0 => $post->ID); $posts_to_query = array_diff($posts_to_query, $_array_diff); } $seed = date('Ymdhi'); // Use date('Ymdh') to get an hourly change $max_random_posts_query = " ORDER BY rand({$seed}) "; // set the query args $defaults = array('ignore_sticky_posts' => 1, 'showposts' => $showposts, 'post_type' => $type, 'post__in' => $posts_to_query, 'orderby' => $rand, 'order' => $sort); // query the posts $queried_posts = query_posts($defaults); $max_random_posts_query = ''; return $queried_posts; }
function ac_portfolio_get_related($post = 0) { $posts = array(); // Get the post $post = get_post($post); // Get the term objects $terms = wp_get_object_terms($post->ID, 'portfolio-category'); // Get the posts for these terms $post_ids = array(); if (count($terms)) { $post_ids = get_objects_in_term($terms[0]->term_id, 'portfolio-category'); } // Remove this post from the list $index = array_search($post->ID, $post_ids); if ($index !== false) { unset($post_ids[$index]); } if ($post_ids) { $args = array('post_type' => 'ac_portfolio', 'post__in' => $post_ids, 'posts_per_page' => 3, 'orderby' => 'meta_value', 'order' => 'date'); $posts = get_posts($args); } return $posts; }
function convert_tags() { global $wpdb; if ((!isset($_POST['tags_to_convert']) || !is_array($_POST['tags_to_convert'])) && empty($this->tags_to_convert)) { echo '<div class="narrow">'; echo '<p>' . sprintf(__('Uh, oh. Something didn’t work. Please <a href="%s">try again</a>.'), 'admin.php?import=wp-cat2tag&step=3') . '</p>'; echo '</div>'; return; } if (empty($this->tags_to_convert)) { $this->tags_to_convert = $_POST['tags_to_convert']; } $hybrid_tags = $clear_parents = false; $clean_cat_cache = $clean_term_cache = array(); $default_cat = get_option('default_category'); echo '<ul>'; foreach ((array) $this->tags_to_convert as $tag_id) { $tag_id = (int) $tag_id; if ($tag = get_term($tag_id, 'post_tag')) { printf('<li>' . __('Converting tag <strong>%s</strong> ... '), $tag->name); if ($cat_ttid = $wpdb->get_var($wpdb->prepare("SELECT term_taxonomy_id FROM {$wpdb->term_taxonomy} WHERE term_id = %d AND taxonomy = 'category'", $tag->term_id))) { $objects_ids = get_objects_in_term($tag->term_id, 'post_tag'); $cat_ttid = (int) $cat_ttid; $term_order = 0; foreach ($objects_ids as $object_id) { $values[] = $wpdb->prepare("(%d, %d, %d)", $object_id, $cat_ttid, $term_order); clean_post_cache($object_id); } if ($values) { $wpdb->query("INSERT INTO {$wpdb->term_relationships} (object_id, term_taxonomy_id, term_order) VALUES " . join(',', $values) . " ON DUPLICATE KEY UPDATE term_order = VALUES(term_order)"); if ($default_cat != $tag->term_id) { $count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM {$wpdb->term_relationships} WHERE term_taxonomy_id = %d", $tag->term_id)); $wpdb->query($wpdb->prepare("UPDATE {$wpdb->term_taxonomy} SET count = %d WHERE term_id = %d AND taxonomy = 'category'", $count, $tag->term_id)); } } $hybrid_tags = true; $clean_term_cache[] = $tag->term_id; $clean_cat_cache[] = $tag->term_id; echo __('All posts were added to the category with the same name.') . " *</li>\n"; continue; } // Change the tag to a category. $parent = $wpdb->get_var($wpdb->prepare("SELECT parent FROM {$wpdb->term_taxonomy} WHERE term_id = %d AND taxonomy = 'post_tag'", $tag->term_id)); if (0 == $parent || 0 < (int) $parent && $this->_category_exists($parent)) { $reset_parent = ''; $clear_parents = true; } else { $reset_parent = ", parent = '0'"; } $wpdb->query($wpdb->prepare("UPDATE {$wpdb->term_taxonomy} SET taxonomy = 'category' {$reset_parent} WHERE term_id = %d AND taxonomy = 'post_tag'", $tag->term_id)); $clean_term_cache[] = $tag->term_id; $clean_cat_cache[] = $cat['term_id']; echo __('Converted successfully.') . "</li>\n"; } else { printf('<li>' . __('Tag #%s doesn\'t exist!') . "</li>\n", $tag_id); } } if (!empty($clean_term_cache)) { $clean_term_cache = array_unique(array_values($clean_term_cache)); foreach ($clean_term_cache as $id) { wp_cache_delete($id, 'post_tag'); } } if (!empty($clean_cat_cache)) { $clean_cat_cache = array_unique(array_values($clean_cat_cache)); foreach ($clean_cat_cache as $id) { wp_cache_delete($id, 'category'); } } if ($clear_parents) { delete_option('category_children'); } echo '</ul>'; if ($hybrid_tags) { echo '<p>' . sprintf(__('* This tag is also a category. The converter has added all posts from it to the category. If you want to remove it, please confirm that all posts were added successfully, then delete it from the <a href="%s">Manage Tags</a> page.'), 'edit-tags.php') . '</p>'; } echo '<p>' . sprintf(__('We’re all done here, but you can always <a href="%s">convert more</a>.'), 'admin.php?import=wp-cat2tag&step=3') . '</p>'; }
/** * Retrieve adjacent post link. * * Can either be next or previous post link. * * Based on get_adjacent_post() from wp-includes/link-template.php * * @param array $r Arguments. * @param bool $previous Optional. Whether to retrieve previous post. * @return array of post objects. */ function fusion_get_adjacent_post_plus($r, $previous = true) { global $post, $wpdb; extract($r, EXTR_SKIP); if (empty($post)) { return null; } // Sanitize $order_by, since we are going to use it in the SQL query. // Default to 'post_date'. switch ($order_by) { case 'post_date': case 'post_title': case 'post_excerpt': case 'post_name': case 'post_modified': $order_format = '%s'; break; case 'ID': case 'post_author': case 'post_parent': case 'menu_order': case 'comment_count': $order_format = '%d'; break; case 'custom' == $order_by && !empty($meta_key): // Don't allow a custom sort if meta_key is empty. $order_format = '%s'; break; case 'numeric' == $order_by && !empty($meta_key): $order_format = '%d'; break; default: $order_by = 'post_date'; $order_format = '%s'; } // Sanitize $order_2nd. // Only columns containing unique values are allowed here. // Default to 'post_date'. switch ($order_2nd) { case 'post_date': case 'post_title': case 'post_modified': $order_format2 = '%s'; break; case 'ID': $order_format2 = '%d'; break; default: $order_2nd = 'post_date'; $order_format2 = '%s'; } // Sanitize num_results (non-integer or negative values trigger SQL errors) $num_results = intval($num_results) < 2 ? 1 : intval($num_results); $current_post = $post->{$order_by}; $order_by = 'p.' . $order_by; $meta_join = ''; // Queries involving custom fields require an extra table join if (in_array($order_by, array('custom', 'numeric'))) { $current_post = get_post_meta($post->ID, $meta_key, true); $order_by = 'numeric' === $order_by ? 'm.meta_value+0' : 'm.meta_value'; $meta_join = $wpdb->prepare(" INNER JOIN {$wpdb->postmeta} AS m ON p.ID = m.post_id AND m.meta_key = %s", $meta_key); } elseif ($in_same_meta) { $current_post = $post->{$order_by}; $order_by = 'p.' . $order_by; $meta_join = $wpdb->prepare(" INNER JOIN {$wpdb->postmeta} AS m ON p.ID = m.post_id AND m.meta_key = %s", $in_same_meta); } // Get the current post value for the second sort column $current_post2 = $post->{$order_2nd}; $order_2nd = 'p.' . $order_2nd; // Get the list of post types. Default to current post type if (empty($post_type)) { $post_type = "'{$post->post_type}'"; } // Put this section in a do-while loop to enable the loop-to-first-post option do { $join = $meta_join; $excluded_categories = $ex_cats; $included_categories = $in_cats; $excluded_posts = $ex_posts; $included_posts = $in_posts; $in_same_term_sql = $in_same_author_sql = $in_same_meta_sql = $ex_cats_sql = $in_cats_sql = $ex_posts_sql = $in_posts_sql = ''; // Get the list of hierarchical taxonomies, including customs (don't assume taxonomy = 'category') $taxonomies = array_filter(get_post_taxonomies($post->ID), "is_taxonomy_hierarchical"); if (($in_same_cat || $in_same_tax || $in_same_format || !empty($excluded_categories) || !empty($included_categories)) && !empty($taxonomies)) { $cat_array = $tax_array = $format_array = array(); if ($in_same_cat) { $cat_array = wp_get_object_terms($post->ID, $taxonomies, array('fields' => 'ids')); } if ($in_same_tax && !$in_same_cat) { if (true === $in_same_tax) { if (array('category') != $taxonomies) { $taxonomies = array_diff($taxonomies, array('category')); } } else { $taxonomies = (array) $in_same_tax; } $tax_array = wp_get_object_terms($post->ID, $taxonomies, array('fields' => 'ids')); } if ($in_same_format) { $taxonomies[] = 'post_format'; $format_array = wp_get_object_terms($post->ID, 'post_format', array('fields' => 'ids')); } $join .= " INNER JOIN {$wpdb->term_relationships} AS tr ON p.ID = tr.object_id INNER JOIN {$wpdb->term_taxonomy} tt ON tr.term_taxonomy_id = tt.term_taxonomy_id AND tt.taxonomy IN (\"" . implode('", "', $taxonomies) . "\")"; $term_array = array_unique(array_merge($cat_array, $tax_array, $format_array)); if (!empty($term_array)) { $in_same_term_sql = "AND tt.term_id IN (" . implode(',', $term_array) . ")"; } if (!empty($excluded_categories)) { // Support for both (1 and 5 and 15) and (1, 5, 15) delimiter styles $delimiter = strpos($excluded_categories, ',') !== false ? ',' : 'and'; $excluded_categories = array_map('intval', explode($delimiter, $excluded_categories)); // Three category exclusion methods are supported: 'strong', 'diff', and 'weak'. // Default is 'weak'. See the plugin documentation for more information. if ('strong' === $ex_cats_method) { $taxonomies = array_filter(get_post_taxonomies($post->ID), 'is_taxonomy_hierarchical'); if (function_exists('get_post_format')) { $taxonomies[] = 'post_format'; } $ex_cats_posts = get_objects_in_term($excluded_categories, $taxonomies); if (!empty($ex_cats_posts)) { $ex_cats_sql = "AND p.ID NOT IN (" . implode($ex_cats_posts, ',') . ")"; } } else { if (!empty($term_array) && !in_array($ex_cats_method, array('diff', 'differential'))) { $excluded_categories = array_diff($excluded_categories, $term_array); } if (!empty($excluded_categories)) { $ex_cats_sql = "AND tt.term_id NOT IN (" . implode($excluded_categories, ',') . ')'; } } } if (!empty($included_categories)) { $in_same_term_sql = ''; // in_cats overrides in_same_cat $delimiter = false !== strpos($included_categories, ',') ? ',' : 'and'; $included_categories = array_map('intval', explode($delimiter, $included_categories)); $in_cats_sql = "AND tt.term_id IN (" . implode(',', $included_categories) . ")"; } } // Optionally restrict next/previous links to same author if ($in_same_author) { $in_same_author_sql = $wpdb->prepare("AND p.post_author = %d", $post->post_author); } // Optionally restrict next/previous links to same meta value if ($in_same_meta && 'custom' != $r['order_by'] && 'numeric' != $r['order_by']) { $in_same_meta_sql = $wpdb->prepare("AND m.meta_value = %s", get_post_meta($post->ID, $in_same_meta, true)); } // Optionally exclude individual post IDs if (!empty($excluded_posts)) { $excluded_posts = array_map('intval', explode(',', $excluded_posts)); $ex_posts_sql = " AND p.ID NOT IN (" . implode(',', $excluded_posts) . ")"; } // Optionally include individual post IDs if (!empty($included_posts)) { $included_posts = array_map('intval', explode(',', $included_posts)); $in_posts_sql = " AND p.ID IN (" . implode(',', $included_posts) . ")"; } $adjacent = $previous ? 'previous' : 'next'; $order = $previous ? 'DESC' : 'ASC'; $op = $previous ? '<' : '>'; // Optionally get the first/last post. Disable looping and return only one result. if ($end_post) { $order = $previous ? 'ASC' : 'DESC'; $num_results = 1; $loop = false; // display the end post link even when it is the current post if ('fixed' === $end_post) { $op = $previous ? '<=' : '>='; } } // If there is no next/previous post, loop back around to the first/last post. if ($loop && isset($result)) { $op = $previous ? '>=' : '<='; // prevent an infinite loop if no first/last post is found $loop = false; } $join = apply_filters("get_{$adjacent}_post_plus_join", $join, $r); // In case the value in the $order_by column is not unique, select posts based on the $order_2nd column as well. // This prevents posts from being skipped when they have, for example, the same menu_order. $where = apply_filters("get_{$adjacent}_post_plus_where", $wpdb->prepare("WHERE ( {$order_by} {$op} {$order_format} OR {$order_2nd} {$op} {$order_format2} AND {$order_by} = {$order_format} ) AND p.post_type IN ({$post_type}) AND p.post_status = 'publish' {$in_same_term_sql} {$in_same_author_sql} {$in_same_meta_sql} {$ex_cats_sql} {$in_cats_sql} {$ex_posts_sql} {$in_posts_sql}", $current_post, $current_post2, $current_post), $r); $sort = apply_filters("get_{$adjacent}_post_plus_sort", "ORDER BY {$order_by} {$order}, {$order_2nd} {$order} LIMIT {$num_results}", $r); $query = "SELECT DISTINCT p.* FROM {$wpdb->posts} AS p {$join} {$where} {$sort}"; $query_key = 'adjacent_post_' . md5($query); $result = wp_cache_get($query_key); if (false !== $result) { return $result; } // Use get_results instead of get_row, in order to retrieve multiple adjacent posts (when $num_results > 1) // Add DISTINCT keyword to prevent posts in multiple categories from appearing more than once $result = $wpdb->get_results("SELECT DISTINCT p.* FROM {$wpdb->posts} AS p {$join} {$where} {$sort}"); $result = null === $result ? '' : $result; } while (!$result && $loop); wp_cache_set($query_key, $result); return $result; }
/** * Check if we will be showing products or not (and not subcats only) * * @access public * @subpackage Loop * @return bool */ function woocommerce_products_will_display() { if (is_shop()) { return get_option('woocommerce_shop_page_display') != 'subcategories'; } if (!is_product_taxonomy()) { return false; } if (is_search() || is_filtered() || is_paged()) { return true; } $term = get_queried_object(); if (is_product_category()) { switch (get_woocommerce_term_meta($term->term_id, 'display_type', true)) { case 'subcategories': // Nothing - we want to continue to see if there are products/subcats break; case 'products': case 'both': return true; break; default: // Default - no setting if (get_option('woocommerce_category_archive_display') != 'subcategories') { return true; } break; } } // Begin subcategory logic global $wpdb; $parent_id = empty($term->term_id) ? 0 : $term->term_id; $taxonomy = empty($term->taxonomy) ? '' : $term->taxonomy; $products_will_display = true; if (!$parent_id && !$taxonomy) { return true; } $transient_name = 'wc_products_will_display_' . $parent_id . WC_Cache_Helper::get_transient_version('product_query'); if (false === ($products_will_display = get_transient($transient_name))) { $has_children = $wpdb->get_col($wpdb->prepare("SELECT term_id FROM {$wpdb->term_taxonomy} WHERE parent = %d AND taxonomy = %s", $parent_id, $taxonomy)); if ($has_children) { // Check terms have products inside - parents first. If products are found inside, subcats will be shown instead of products so we can return false. if (sizeof(get_objects_in_term($has_children, $taxonomy)) > 0) { $products_will_display = false; } else { // If we get here, the parents were empty so we're forced to check children foreach ($has_children as $term) { $children = get_term_children($term, $taxonomy); if (sizeof(get_objects_in_term($children, $taxonomy)) > 0) { $products_will_display = false; break; } } } } else { $products_will_display = true; } } set_transient($transient_name, $products_will_display, YEAR_IN_SECONDS); return $products_will_display; }
function _use_categories_in_all_languages($product_ids, $category_id) { global $sitepress; $category_term = get_term($category_id, 'product_cat'); if (!is_wp_error($category_term)) { $trid = $sitepress->get_element_trid($category_term->term_taxonomy_id, 'tax_product_cat'); $translations = $sitepress->get_element_translations($trid, 'tax_product_cat', true); foreach ($translations as $translation) { if ($translation->term_id != $category_id) { $term_ids = get_term_children($translation->term_id, 'product_cat'); $term_ids[] = $translation->term_id; $product_ids = array_merge(array_unique($product_ids), get_objects_in_term($term_ids, 'product_cat')); } } } return $product_ids; }
/** * widget function. * * @see WP_Widget * @access public * @param array $args * @param array $instance * @return void */ function widget($args, $instance) { extract($args); global $_chosen_attributes, $woocommerce, $_attributes_array; if (!is_post_type_archive('product') && !is_tax(array_merge($_attributes_array, array('product_cat', 'product_tag')))) { return; } $current_term = $_attributes_array && is_tax($_attributes_array) ? get_queried_object()->term_id : ''; $current_tax = $_attributes_array && is_tax($_attributes_array) ? get_queried_object()->taxonomy : ''; $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); $taxonomy = $woocommerce->attribute_taxonomy_name($instance['attribute']); $query_type = isset($instance['query_type']) ? $instance['query_type'] : 'and'; $display_type = isset($instance['display_type']) ? $instance['display_type'] : 'list'; if (!taxonomy_exists($taxonomy)) { return; } $args = array('hide_empty' => '1'); $terms = get_terms($taxonomy, $args); $count = count($terms); if ($count > 0) { $found = false; ob_start(); echo $before_widget . $before_title . $title . $after_title; // Force found when option is selected - do not force found on taxonomy attributes if (!$_attributes_array || !is_tax($_attributes_array)) { if (is_array($_chosen_attributes) && array_key_exists($taxonomy, $_chosen_attributes)) { $found = true; } } if ($display_type == 'dropdown') { // skip when viewing the taxonomy if ($current_tax && $taxonomy == $current_tax) { $found = false; } else { $taxonomy_filter = str_replace('pa_', '', $taxonomy); $found = true; echo '<select id="dropdown_layered_nav_' . $taxonomy_filter . '">'; echo '<option value="">' . sprintf(__('Any %s', 'woocommerce'), $woocommerce->attribute_label($taxonomy)) . '</option>'; foreach ($terms as $term) { // If on a term page, skip that term in widget list if ($term->term_id == $current_term) { continue; } // Get count based on current view - uses transients $transient_name = 'wc_ln_count_' . md5(sanitize_key($taxonomy) . sanitize_key($term->term_id)); if (false === ($_products_in_term = get_transient($transient_name))) { $_products_in_term = get_objects_in_term($term->term_id, $taxonomy); set_transient($transient_name, $_products_in_term); } $option_is_set = isset($_chosen_attributes[$taxonomy]) && in_array($term->term_id, $_chosen_attributes[$taxonomy]['terms']); // If this is an AND query, only show options with count > 0 if ($query_type == 'and') { $count = sizeof(array_intersect($_products_in_term, $woocommerce->query->filtered_product_ids)); if ($count > 0) { $found = true; } if ($count == 0 && !$option_is_set) { continue; } // If this is an OR query, show all options so search can be expanded } else { $count = sizeof(array_intersect($_products_in_term, $woocommerce->query->unfiltered_product_ids)); if ($count > 0) { $found = true; } } echo '<option value="' . $term->term_id . '" ' . selected(isset($_GET['filter_' . $taxonomy_filter]) ? $_GET['filter_' . $taxonomy_filter] : '', $term->term_id, false) . '>' . $term->name . '</option>'; } echo '</select>'; $woocommerce->add_inline_js("\n\n\t\t\t\t\t\tjQuery('#dropdown_layered_nav_{$taxonomy_filter}').change(function(){\n\n\t\t\t\t\t\t\tlocation.href = '" . add_query_arg('filtering', '1', remove_query_arg('filter_' . $taxonomy_filter)) . "&filter_{$taxonomy_filter}=' + jQuery('#dropdown_layered_nav_{$taxonomy_filter}').val();\n\n\t\t\t\t\t\t});\n\n\t\t\t\t\t"); } } else { // List display echo "<ul>"; foreach ($terms as $term) { // Get count based on current view - uses transients $transient_name = 'wc_ln_count_' . md5(sanitize_key($taxonomy) . sanitize_key($term->term_id)); if (false === ($_products_in_term = get_transient($transient_name))) { $_products_in_term = get_objects_in_term($term->term_id, $taxonomy); set_transient($transient_name, $_products_in_term); } $option_is_set = isset($_chosen_attributes[$taxonomy]) && in_array($term->term_id, $_chosen_attributes[$taxonomy]['terms']); // If this is an AND query, only show options with count > 0 if ($query_type == 'and') { $count = sizeof(array_intersect($_products_in_term, $woocommerce->query->filtered_product_ids)); // skip the term for the current archive if ($current_term == $term->term_id) { continue; } if ($count > 0 && $current_term !== $term->term_id) { $found = true; } if ($count == 0 && !$option_is_set) { continue; } // If this is an OR query, show all options so search can be expanded } else { // skip the term for the current archive if ($current_term == $term->term_id) { continue; } $count = sizeof(array_intersect($_products_in_term, $woocommerce->query->unfiltered_product_ids)); if ($count > 0) { $found = true; } } $class = ''; $arg = 'filter_' . strtolower(sanitize_title($instance['attribute'])); if (isset($_GET[$arg])) { $current_filter = explode(',', $_GET[$arg]); } else { $current_filter = array(); } if (!is_array($current_filter)) { $current_filter = array(); } if (!in_array($term->term_id, $current_filter)) { $current_filter[] = $term->term_id; } // Base Link decided by current page if (defined('SHOP_IS_ON_FRONT')) { $link = home_url(); } elseif (is_post_type_archive('product') || is_page(woocommerce_get_page_id('shop'))) { $link = get_post_type_archive_link('product'); } else { $link = get_term_link(get_query_var('term'), get_query_var('taxonomy')); } // All current filters if ($_chosen_attributes) { foreach ($_chosen_attributes as $name => $data) { if ($name !== $taxonomy) { //exclude query arg for current term archive term while (in_array($current_term, $data['terms'])) { $key = array_search($current_term, $data); unset($data['terms'][$key]); } if (!empty($data['terms'])) { $link = add_query_arg(strtolower(sanitize_title(str_replace('pa_', 'filter_', $name))), implode(',', $data['terms']), $link); } if ($data['query_type'] == 'or') { $link = add_query_arg(strtolower(sanitize_title(str_replace('pa_', 'query_type_', $name))), 'or', $link); } } } } // Min/Max if (isset($_GET['min_price'])) { $link = add_query_arg('min_price', $_GET['min_price'], $link); } if (isset($_GET['max_price'])) { $link = add_query_arg('max_price', $_GET['max_price'], $link); } // Current Filter = this widget if (isset($_chosen_attributes[$taxonomy]) && is_array($_chosen_attributes[$taxonomy]['terms']) && in_array($term->term_id, $_chosen_attributes[$taxonomy]['terms'])) { $class = 'class="chosen"'; // Remove this term is $current_filter has more than 1 term filtered if (sizeof($current_filter) > 1) { $current_filter_without_this = array_diff($current_filter, array($term->term_id)); $link = add_query_arg($arg, implode(',', $current_filter_without_this), $link); } } else { $link = add_query_arg($arg, implode(',', $current_filter), $link); } // Search Arg if (get_search_query()) { $link = add_query_arg('s', get_search_query(), $link); } // Post Type Arg if (isset($_GET['post_type'])) { $link = add_query_arg('post_type', $_GET['post_type'], $link); } // Query type Arg if ($query_type == 'or' && !(sizeof($current_filter) == 1 && isset($_chosen_attributes[$taxonomy]['terms']) && is_array($_chosen_attributes[$taxonomy]['terms']) && in_array($term->term_id, $_chosen_attributes[$taxonomy]['terms']))) { $link = add_query_arg('query_type_' . strtolower(sanitize_title($instance['attribute'])), 'or', $link); } echo '<li ' . $class . '>'; if ($count > 0 || $option_is_set) { echo '<a href="' . $link . '">'; } else { echo '<span>'; } echo $term->name; if ($count > 0 || $option_is_set) { echo '</a>'; } else { echo '</span>'; } echo ' <small class="count">' . $count . '</small></li>'; } echo "</ul>"; } // End display type conditional echo $after_widget; if (!$found) { ob_clean(); return; } else { $widget = ob_get_clean(); echo $widget; } } }
/** * Search for gruoped products and return json */ public static function json_search_grouped_products() { ob_start(); check_ajax_referer('search-products', 'security'); $term = (string) wc_clean(stripslashes($_GET['term'])); $exclude = array(); if (empty($term)) { die; } if (!empty($_GET['exclude'])) { $exclude = array_map('intval', explode(',', $_GET['exclude'])); } $found_products = array(); if ($grouped_term = get_term_by('slug', 'grouped', 'product_type')) { $posts_in = array_unique((array) get_objects_in_term($grouped_term->term_id, 'product_type')); if (sizeof($posts_in) > 0) { $args = array('post_type' => 'product', 'post_status' => 'any', 'numberposts' => -1, 'orderby' => 'title', 'order' => 'asc', 'post_parent' => 0, 'suppress_filters' => 0, 'include' => $posts_in, 's' => $term, 'fields' => 'ids', 'exclude' => $exclude); $posts = get_posts($args); if (!empty($posts)) { foreach ($posts as $post) { $product = wc_get_product($post); if (!current_user_can('read_product', $post)) { continue; } $found_products[$post] = rawurldecode($product->get_formatted_name()); } } } } $found_products = apply_filters('woocommerce_json_search_found_grouped_products', $found_products); wp_send_json($found_products); }
/** * When updating jobs via ajax, get tag cloud * @param array $results * @return array */ public function job_manager_get_listings_result($results) { if (isset($_REQUEST['form_data'])) { parse_str($_REQUEST['form_data'], $params); if (isset($params['is_job_listing_tag'])) { return $results; } } $html = ''; $search_categories = isset($_REQUEST['search_categories']) ? $_REQUEST['search_categories'] : ''; if (is_array($search_categories)) { $search_categories = array_filter(array_map('sanitize_text_field', array_map('stripslashes', $search_categories))); } else { $search_categories = array_filter(array(sanitize_text_field(stripslashes($search_categories)))); } if ($search_categories) { // Get IDS foreach ($search_categories as $key => $search_category) { if (!is_numeric($search_category)) { $category_object = get_term_by('slug', $search_category, 'job_listing_category'); $search_categories[$key] = $category_object->term_id; } } $transient_key = md5(implode(',', $search_categories)); $transient = array_filter((array) get_transient('job_tag_q')); if (empty($transient[$transient_key])) { foreach ($search_categories as $search_category) { $search_categories = array_merge($search_categories, get_term_children($search_category, 'job_listing_category')); } $jobs_in_category = get_objects_in_term(array_unique($search_categories), 'job_listing_category'); $include_tags = array(); foreach ($jobs_in_category as $job_id) { $terms = wp_get_post_terms($job_id, 'job_listing_tag', array('fields' => 'ids')); if (is_array($terms)) { $include_tags = array_merge($include_tags, $terms); } $include_tags = array_unique($include_tags); } $transient[$transient_key] = $include_tags; set_transient('job_tag_q', $transient, DAY_IN_SECONDS * 30); } else { $include_tags = $transient[$transient_key]; } } else { $include_tags = true; } if (!empty($include_tags)) { $atts = array('smallest' => 1, 'largest' => 2, 'unit' => 'em', 'number' => 25, 'format' => 'flat', 'separator' => "\n", 'orderby' => 'count', 'order' => 'DESC', 'exclude' => null, 'link' => 'view', 'taxonomy' => 'job_listing_tag', 'echo' => false, 'topic_count_text_callback' => array($this, 'tag_cloud_text_callback'), 'include' => is_array($include_tags) ? implode(',', $include_tags) : null); $html = wp_tag_cloud(apply_filters('job_filter_tag_cloud', $atts)); $html = preg_replace("/<a(.*)href='([^'']*)'(.*)>/", '<a href="#"$1$3>', $html); } $results['tag_filter'] = $html; return $results; }
function recent_tags($num_to_show) { $cache = wp_cache_get('p2_recent_tags', 'widget'); if (!is_array($cache)) { $cache = array(); } if (isset($cache[$num_to_show]) && is_array($cache[$num_to_show])) { return $cache[$num_to_show]; } $all_tags = (array) get_tags(array('get' => 'all')); $post_ids_and_tags = array(); foreach ($all_tags as $tag) { if ($tag->count < 1) { continue; } $recent_post_id = max(get_objects_in_term($tag->term_id, 'post_tag')); $post_ids_and_tags[] = array('post_id' => $recent_post_id, 'tag' => $tag); } usort($post_ids_and_tags, create_function('$a, $b', 'return $b["post_id"] - $a["post_id"];')); $post_ids_and_tags = array_slice($post_ids_and_tags, 0, $num_to_show); $recent_tags = array(); foreach ($post_ids_and_tags as $v) { $recent_tags[] = array('tag' => $v['tag'], 'link' => get_tag_link($v['tag']->term_id), 'feed_link' => get_tag_feed_link($v['tag']->term_id)); } $cache[$num_to_show] = $recent_tags; wp_cache_add('p2_recent_tags', $cache, 'widget'); return $recent_tags; }
function prologue_recent_projects($num_to_show = 35, $before = '', $after = '') { $cache = wp_cache_get('prologue_theme_tag_list', ''); if (!empty($cache[$num_to_show])) { $recent_tags = $cache[$num_to_show]; } else { $all_tags = (array) get_tags(array('get' => 'all')); $recent_tags = array(); foreach ($all_tags as $tag) { if ($tag->count < 1) { continue; } $tag_posts = get_objects_in_term($tag->term_id, 'post_tag'); $recent_post_id = max($tag_posts); $recent_tags[$tag->term_id] = $recent_post_id; } arsort($recent_tags); $num_tags = count($recent_tags); if ($num_tags > $num_to_show) { $reduce_by = (int) $num_tags - $num_to_show; for ($i = 0; $i < $reduce_by; $i++) { array_pop($recent_tags); } } wp_cache_set('prologue_theme_tag_list', array($num_to_show => $recent_tags)); } echo $before; echo "<ul>\n"; foreach ($recent_tags as $term_id => $post_id) { $tag = get_term($term_id, 'post_tag'); $tag_link = get_tag_link($tag->term_id); ?> <li> <a class="rss" href="<?php echo get_tag_feed_link($tag->term_id); ?> ">RSS</a> <a href="<?php echo $tag_link; ?> "><?php echo $tag->name; ?> </a> ( <?php echo $tag->count; ?> ) </li> <?php } // foreach get_tags ?> </ul> <p><a class="allrss" href="<?php bloginfo('rss2_url'); ?> ">All Updates RSS</a></p> <?php echo $after; }
/** * Return products in a given term, and cache value. * * To keep in sync, product_count will be cleared on "set_object_terms". * * @param int $term_id * @param string $taxonomy * @return array */ function wc_get_term_product_ids($term_id, $taxonomy) { $product_ids = get_woocommerce_term_meta($term_id, 'product_ids', true); if (false === $product_ids || !is_array($product_ids)) { $product_ids = get_objects_in_term($term_id, $taxonomy); update_woocommerce_term_meta($term_id, 'product_ids', $product_ids); } return $product_ids; }
/** * Collect products from category translations * * Add all products in the given category translations * * @param array $productIDS array of products in the given category * @param integer $categoryID category ID * * @return array array of producs in the given category and its translations */ public function addProductsInCategoryTranslations($productIDS, $categoryID) { if (static::isCombine()) { /* Find the category translations */ $translations = Utilities::getTermTranslationsArrayByID($categoryID); foreach ($translations as $slug => $ID) { if ($ID === $categoryID) { continue; } $termIDS = get_term_children($ID, 'product_cat'); $termIDS[] = $ID; $productIDS = array_merge($productIDS, (array) get_objects_in_term($termIDS, 'product_cat')); } } return $productIDS; }
/** * Returns all menu items of a navigation menu. * * @since 3.0.0 * * @param string $menu menu name, id, or slug * @param string $args * @return mixed $items array of menu items, else false. */ function wp_get_nav_menu_items($menu, $args = array()) { $menu = wp_get_nav_menu_object($menu); if (!$menu) { return false; } static $fetched = array(); $items = get_objects_in_term($menu->term_id, 'nav_menu'); if (empty($items)) { return $items; } $defaults = array('order' => 'ASC', 'orderby' => 'menu_order', 'post_type' => 'nav_menu_item', 'post_status' => 'publish', 'output' => ARRAY_A, 'output_key' => 'menu_order', 'nopaging' => true); $args = wp_parse_args($args, $defaults); if (count($items) > 1) { $args['include'] = implode(',', $items); } else { $args['include'] = $items[0]; } $items = get_posts($args); if (is_wp_error($items) || !is_array($items)) { return false; } // Get all posts and terms at once to prime the caches if (empty($fetched[$menu->term_id]) || wp_using_ext_object_cache()) { $fetched[$menu->term_id] = true; $posts = array(); $terms = array(); foreach ($items as $item) { $object_id = get_post_meta($item->ID, '_menu_item_object_id', true); $object = get_post_meta($item->ID, '_menu_item_object', true); $type = get_post_meta($item->ID, '_menu_item_type', true); if ('post_type' == $type) { $posts[$object][] = $object_id; } elseif ('taxonomy' == $type) { $terms[$object][] = $object_id; } } if (!empty($posts)) { foreach (array_keys($posts) as $post_type) { get_posts(array('post__in' => $posts[$post_type], 'post_type' => $post_type, 'nopaging' => true, 'update_post_term_cache' => false)); } } unset($posts); if (!empty($terms)) { foreach (array_keys($terms) as $taxonomy) { get_terms($taxonomy, array('include' => $terms[$taxonomy])); } } unset($terms); } $items = array_map('wp_setup_nav_menu_item', $items); if (!is_admin()) { // Remove invalid items only in frontend $items = array_filter($items, '_is_valid_nav_menu_item'); } if (ARRAY_A == $args['output']) { $GLOBALS['_menu_item_sort_prop'] = $args['output_key']; usort($items, '_sort_nav_menu_items'); $i = 1; foreach ($items as $k => $item) { $items[$k]->{$args}['output_key'] = $i++; } } /** * Filter the navigation menu items being returned. * * @since 3.0.0 * * @param array $items An array of menu item post objects. * @param object $menu The menu object. * @param array $args An array of arguments used to retrieve menu item objects. */ return apply_filters('wp_get_nav_menu_items', $items, $menu, $args); }
/** * Return true if the term has a child, false otherwise * * @param $term The term object * @param $taxonomy the taxonomy to search * * @return bool * * @since 1.3.1 */ function yit_term_has_child($term, $taxonomy) { global $woocommerce; $count = 0; $child_terms = get_terms($taxonomy, array('child_of' => $term->term_id)); if (!is_wp_error($child_terms)) { foreach ($child_terms as $child_term) { $_products_in_term = get_objects_in_term($child_term->term_id, $taxonomy); $count += sizeof(array_intersect($_products_in_term, $woocommerce->query->filtered_product_ids)); } } return empty($count) ? false : true; }
/** * has_assignments( $group_id = null ) * * Checks if a $group_id has assignments * * @param Int $group_id of the group to be checked * @return Mixed Assignment objects if assignments exist and null if not. */ function has_assignments($group_id = null) { global $bp; $assignment_ids = null; $assignments = array(); if (empty($group_id)) { $group_id = $bp->groups->current_group->id; } $term_id = get_term_by('slug', $group_id, 'group_id'); if (!empty($term_id)) { $assignment_ids = get_objects_in_term($term_id->term_id, 'group_id'); } if (!empty($assignment_ids)) { arsort($assignment_ids); } else { return null; } foreach ($assignment_ids as $aid) { $assignments[] = self::is_assignment($aid); } return array_filter($assignments); }
/** * get_posts( $terms, $post_types, $s ) * * A hack to query multiple custom terms * Left for backwards compatibility, on the removal list! * * @param Mixed $terms, a set of term slugs as keys and taxonomies as values * @param Mixed $post_types, a set of post types to query * @param String $s to search for * @return Mixed $posts, a set of queried posts */ function get_posts($terms, $post_types = null, $s = null) { if (!$post_types) { $post_types = array('post'); } $term_ids = array(); $post_ids = array(); $posts = array(); // Get term ids // TODO: Here's something wrong, totally!!! foreach ($terms as $term => $taxonomy) { $t = get_term_by('slug', $taxonomy, $term); if (!empty($t)) { $term_ids[$t->term_id] = $term; } } // Get term's objects if (!empty($term_ids)) { foreach ($term_ids as $term_id => $taxonomy) { $post_ids[] = get_objects_in_term($term_id, $taxonomy); } } // Get common objects if (!empty($post_ids)) { for ($i = 1; $i < count($post_ids); $i++) { $post_ids[0] = array_intersect($post_ids[0], $post_ids[$i]); } // return the final array $post_ids = reset($post_ids); } // Get object data's of one type if (!empty($post_ids) && is_array($post_ids)) { return get_posts(array('post__in' => $post_ids, 'post_type' => $post_types, 's' => $s)); } else { return null; } }