本文整理汇总了PHP中get_objects_in_term函数的典型用法代码示例。如果您正苦于以下问题:PHP get_objects_in_term函数的具体用法?PHP get_objects_in_term怎么用?PHP get_objects_in_term使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_objects_in_term函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: jr_process_filter_form
/**
* 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;
}
示例2: get_products_in_category
/**
* 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));
}
示例3: get_letters_in_snap
/**
* 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) );
}
示例4: mf_sponsor_list
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;
}
示例5: multiple_tax_fix
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);
}
示例6: wcapf_get_term_objects
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;
}
示例7: get_posts_related_by_taxonomy
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;
}
示例8: fontello_conversion
/**
* 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;
}
示例9: jigoshop_product_type_options_box
/**
* 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');
}
示例10: get_posts_related_by_taxonomy
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;
}
示例11: get_posts_related_by_taxonomy
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;
}
示例12: handle_duplicate
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);
}
}
}
}
}
示例13: go_gold_store_sc
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>';
}
}
}
}
示例14: max_query_term_posts
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;
}
示例15: ac_portfolio_get_related
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;
}