本文整理汇总了PHP中wp_get_object_terms函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_get_object_terms函数的具体用法?PHP wp_get_object_terms怎么用?PHP wp_get_object_terms使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_get_object_terms函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: manage_screen_options_columns
function manage_screen_options_columns($column, $post_id)
{
global $post;
$chosen_client_id = get_post_meta($post_id, 'chosen_client', true);
switch ($column) {
case 'invnumber':
$invnumber = get_post_meta($post_id, 'invoice_serial_number', true);
echo "№ " . str_pad($invnumber, 10, "0", STR_PAD_LEFT);
break;
case 'company_name':
$company_name = get_post_meta($chosen_client_id, 'company_name', true);
if (empty($company_name)) {
echo __('Unknown');
} else {
echo __($company_name);
}
break;
case 'status':
$status = wp_get_object_terms($post_id, 'status');
if (empty($status)) {
echo __(' - ');
} else {
foreach ($status as $the_status) {
echo $the_status->name . " ";
}
}
default:
break;
}
}
示例2: prepare_items
public function prepare_items()
{
if (!empty($this->items)) {
return;
}
$per_page = $this->get_items_per_page('edit_wpsc-product-variations_per_page');
$per_page = apply_filters('edit_wpsc_product_variations_per_page', $per_page);
$this->args = array('post_type' => 'wpsc-product', 'orderby' => 'menu_order title', 'post_parent' => $this->product_id, 'post_status' => 'publish, inherit', 'numberposts' => -1, 'order' => "ASC", 'posts_per_page' => $per_page);
if (isset($_REQUEST['post_status'])) {
$this->args['post_status'] = $_REQUEST['post_status'];
}
if (isset($_REQUEST['s'])) {
$this->args['s'] = $_REQUEST['s'];
}
if (isset($_REQUEST['paged'])) {
$this->args['paged'] = $_REQUEST['paged'];
}
$query = new WP_Query($this->args);
$this->items = $query->posts;
$total_items = $query->found_posts;
$total_pages = $query->max_num_pages;
$this->set_pagination_args(array('total_items' => $total_items, 'total_pages' => $total_pages, 'per_page' => $per_page));
if (empty($this->items)) {
return;
}
$ids = wp_list_pluck($this->items, 'ID');
$object_terms = wp_get_object_terms($ids, 'wpsc-variation', array('fields' => 'all_with_object_id'));
foreach ($object_terms as $term) {
if (!array_key_exists($term->object_id, $this->object_terms_cache)) {
$this->object_terms_cache[$term->object_id] = array();
}
$this->object_terms_cache[$term->object_id][$term->parent] = $term->name;
}
}
示例3: filter_content
public function filter_content($content)
{
// Get Templates
$templates = self::get_option('rwp_templates');
$terms = wp_get_object_terms(get_the_ID(), array_keys(get_taxonomies()));
$terms_keys = array();
foreach ($terms as $term) {
$terms_keys[$term->taxonomy][] = $term->term_id;
}
//self::pretty_print( $terms_keys );
foreach ($templates as $template) {
if (isset($template['template_auto_reviews']) && !empty($template['template_auto_reviews'])) {
if (is_singular($template['template_auto_reviews']) && is_main_query()) {
if (isset($template['template_exclude_terms'])) {
$to_exclude = false;
foreach ($template['template_exclude_terms'] as $id) {
$i = explode('-', $id);
if (in_array($i[1], $terms_keys[$i[0]])) {
$to_exclude = true;
break;
}
}
if ($to_exclude) {
continue;
}
}
$new_content = '[rwp-review id="-1" template="' . $template['template_id'] . '"]';
$content .= $new_content;
}
}
}
return $content;
}
示例4: generate_tag_cloud
function generate_tag_cloud($post_type)
{
global $wpdb;
// database calls must be sensitive to multisite
$query = $wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type = %s", $post_type);
$attachment_ids = $wpdb->get_col($query);
$terms = wp_get_object_terms($attachment_ids, 'post_tag', array('orderby' => 'count', 'order' => 'DESC'));
$tags = array();
// limit to 45 tags
foreach ($terms as $term) {
$tags[$term->term_id] = $term;
if (count($tags) >= 45) {
break;
}
}
if (empty($tags)) {
die(__('No tags found!', THEMEDOMAIN));
}
if (is_wp_error($tags)) {
die($tags->get_error_message());
}
foreach ($tags as $key => $tag) {
$tags[$key]->link = '#';
$tags[$key]->id = $tag->term_id;
}
// We need raw tag names here, so don't filter the output
$return = wp_generate_tag_cloud($tags, array('filter' => 0));
if (empty($return)) {
die('0');
}
echo $return;
exit;
}
示例5: type_permalink
function type_permalink($permalink, $post_id, $leavename)
{
if (strpos($permalink, '%event_type%') === FALSE) {
return $permalink;
}
if (strpos($permalink, '%event_place%') === FALSE) {
return $permalink;
}
// Get post
$post = get_post($post_id);
if (!$post) {
return $permalink;
}
// Get taxonomy terms
$terms = wp_get_object_terms($post->ID, 'event_type');
if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0])) {
$taxonomy_slug = $terms[0]->slug;
} else {
$taxonomy_slug = 'no-type';
}
return str_replace('%event_type%', $taxonomy_slug, $permalink);
// Get taxonomy terms
$terms = wp_get_object_terms($post->ID, 'event_place');
if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0])) {
$taxonomy_slug = $terms[0]->slug;
} else {
$taxonomy_slug = 'no-place';
}
return str_replace('%event_place%', $taxonomy_slug, $permalink);
}
示例6: widget
/**
* widget function.
*
* @see WP_Widget
* @access public
* @param array $args
* @param array $instance
* @return void
*/
function widget($args, $instance)
{
if ($this->get_cached_widget($args)) {
return;
}
if (!class_exists('WP_Job_Manager_Job_Tags')) {
return;
}
global $job_manager, $post;
extract($args);
$title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base);
$icon = isset($instance['icon']) ? $instance['icon'] : null;
if ($icon) {
$before_title = sprintf($before_title, 'ion-' . $icon);
}
$tags = wp_get_object_terms($post->ID, 'job_listing_tag');
if (is_wp_error($tags) || empty($tags)) {
return;
}
ob_start();
echo $before_widget;
if ($title) {
echo $before_title . $title . $after_title;
}
do_action('listify_widget_job_listing_tags_before');
wp_terms_checklist($post->ID, array('taxonomy' => 'job_listing_tag', 'checked_ontop' => false, 'walker' => new Listify_Walker_Tags_Checklist()));
do_action('listify_widget_job_listing_tags_after');
echo $after_widget;
$content = ob_get_clean();
echo apply_filters($this->widget_id, $content);
$this->cache_widget($args, $content);
}
示例7: convert
/**
* convert post data to an object with meta data
* @param object $post
* @return post object after convert
* - wp_error object if post invalid
* @author Dakachi
* @since 1.0
*/
public function convert($post)
{
$result = array();
$post = (array) $post;
/**
* convert need post data
*/
foreach ($this->convert as $key) {
if (isset($post[$key])) {
$result[$key] = $post[$key];
}
}
// generate post taxonomy
if (!empty($this->taxs)) {
foreach ($this->taxs as $name) {
$result[$name] = wp_get_object_terms($post['ID'], $name);
}
}
// generate meta data
if (!empty($this->meta)) {
foreach ($this->meta as $key) {
$result[$key] = get_post_meta($post['ID'], $key, true);
}
}
unset($result['post_password']);
$result['id'] = $post['ID'];
/**
* assign convert post to current post
*/
$this->current_post = apply_filters('ae_convert_post', (object) $result);
return $this->current_post;
}
示例8: get_values_for_product
/**
* Retrieve the values that should be output for a particular product
* Takes into account store defaults, category defaults, and per-product
* settings
*
* @access public
* @param int $product_id The ID of the product to retrieve info for
* @param string $feed_format The feed format being generated
* @param boolean $defaults_only Whether to retrieve the
* store/category defaults only
* @return array The values for the product
*/
public function get_values_for_product($product_id = null, $feed_format = 'all', $defaults_only = false)
{
if (!$product_id) {
return false;
}
// Get Store defaults
$settings = $this->remove_blanks($this->settings['product_defaults']);
if ($feed_format != 'all') {
$settings = $this->remove_other_feeds($settings, $feed_format);
}
// Merge category settings
$categories = wp_get_object_terms($product_id, 'product_cat', array('fields' => 'ids'));
foreach ($categories as $category_id) {
$category_settings = $this->get_values_for_category($category_id);
$category_settings = $this->remove_blanks($category_settings);
if ($feed_format != 'all') {
$category_settings = $this->remove_other_feeds($category_settings, $feed_format);
}
if ($category_settings) {
$settings = array_merge($settings, $category_settings);
}
}
if ($defaults_only) {
return $settings;
}
// Merge product settings
$product_settings = get_post_meta($product_id, '_woocommerce_gpf_data', true);
if ($product_settings) {
$product_settings = $this->remove_blanks($product_settings);
$settings = array_merge($settings, $product_settings);
}
return $settings;
}
示例9: export_csv
function export_csv()
{
global $simple_map, $sm_locations;
if (isset($_POST['sm-action']) && 'export-csv' == $_POST['sm-action']) {
// Grab locations
$content = array();
set_time_limit(0);
$location_offset = 0;
while ($locations = query_posts(array('post_status' => 'publish', 'post_type' => 'sm-location', 'posts_per_page' => 200, 'offset' => $location_offset))) {
// Include CSV library
require_once SIMPLEMAP_PATH . '/classes/parsecsv.lib.php';
$taxonomies = get_object_taxonomies('sm-location');
foreach ($locations as $key => $location) {
$location_offset++;
$location_data = array('name' => esc_attr($location->post_title), 'address' => esc_attr(get_post_meta($location->ID, 'location_address', true)), 'address2' => esc_attr(get_post_meta($location->ID, 'location_address2', true)), 'city' => esc_attr(get_post_meta($location->ID, 'location_city', true)), 'state' => esc_attr(get_post_meta($location->ID, 'location_state', true)), 'zip' => esc_attr(get_post_meta($location->ID, 'location_zip', true)), 'country' => esc_attr(get_post_meta($location->ID, 'location_country', true)), 'phone' => esc_attr(get_post_meta($location->ID, 'location_phone', true)), 'email' => esc_attr(get_post_meta($location->ID, 'location_email', true)), 'fax' => esc_attr(get_post_meta($location->ID, 'location_fax', true)), 'url' => esc_attr(get_post_meta($location->ID, 'location_url', true)), 'description' => esc_attr($location->post_content), 'special' => esc_attr(get_post_meta($location->ID, 'location_special', true)), 'lat' => esc_attr(get_post_meta($location->ID, 'location_lat', true)), 'lng' => esc_attr(get_post_meta($location->ID, 'location_lng', true)), 'dateUpdated' => esc_attr($location->post_modified));
foreach ($taxonomies as $tax) {
$term_value = '';
if ($terms = wp_get_object_terms($location->ID, $tax, array('fields' => 'names'))) {
$term_value = implode(',', $terms);
}
$location_data["tax_{$tax}"] = esc_attr($term_value);
}
$content[] = $location_data;
}
}
if (!empty($content)) {
$csv = new smParseCSV();
$csv->output(true, 'simplemap.csv', $content, array_keys(reset($content)));
die;
}
}
}
示例10: get_offer_categories
function get_offer_categories($post_id = null, $args = array())
{
if (null === $post_id) {
return get_terms('circleflip-offer-category');
}
return wp_get_object_terms($post_id, 'circleflip-offer-category', $args);
}
示例11: wpsc_variations
function wpsc_variations($product_id)
{
global $wpdb;
$product_terms = wp_get_object_terms($product_id, 'wpsc-variation');
$this->variation_groups = array();
$this->first_variations = array();
$this->all_associated_variations = array();
foreach ($product_terms as $product_term) {
if ($product_term->parent > 0) {
if (empty($this->all_associated_variations[$product_term->parent])) {
$this->all_associated_variations[$product_term->parent][0] = new stdClass();
$this->all_associated_variations[$product_term->parent][0]->term_id = 0;
$this->all_associated_variations[$product_term->parent][0]->name = '-- Escolha --';
}
$this->all_associated_variations[$product_term->parent][] = $product_term;
} else {
$this->variation_groups[] = $product_term;
}
}
foreach ((array) $this->variation_groups as $variation_group) {
$variation_id = $variation_group->term_id;
$this->first_variations[] = $this->all_associated_variations[$variation_id][0]->term_id;
}
$this->variation_group_count = count($this->variation_groups);
}
示例12: test_function_post_created
/**
* Test that a post is created for the function.
*/
public function test_function_post_created()
{
$posts = get_posts(array('post_type' => $this->importer->post_type_function));
$this->assertCount(1, $posts);
$post = $posts[0];
// Check that the post attributes are correct.
$this->assertEquals('<p>This function is just here for tests. This is its longer description.</p>', $post->post_content);
$this->assertEquals('This is a function summary.', $post->post_excerpt);
$this->assertEquals('wp_parser_test_func', $post->post_name);
$this->assertEquals(0, $post->post_parent);
$this->assertEquals('wp_parser_test_func', $post->post_title);
// It should be assigned to the file's taxonomy term.
$terms = wp_get_object_terms($post->ID, $this->importer->taxonomy_file);
$this->assertCount(1, $terms);
$this->assertEquals('file.inc', $terms[0]->name);
// It should be assigned to the correct @since taxonomy term.
$terms = wp_get_object_terms($post->ID, $this->importer->taxonomy_since_version);
$this->assertCount(1, $terms);
$this->assertEquals('1.4.0', $terms[0]->name);
// It should be assigned the correct @package taxonomy term.
$terms = wp_get_object_terms($post->ID, $this->importer->taxonomy_package);
$this->assertCount(1, $terms);
$this->assertEquals('Something', $terms[0]->name);
// Check that the metadata was imported.
$this->assertEquals(array(array('name' => '$var', 'default' => null, 'type' => ''), array('name' => '$ids', 'default' => 'array()', 'type' => 'array')), get_post_meta($post->ID, '_wp-parser_args', true));
$this->assertEquals(25, get_post_meta($post->ID, '_wp-parser_line_num', true));
$this->assertEquals(28, get_post_meta($post->ID, '_wp-parser_end_line_num', true));
$this->assertEquals(array(array('name' => 'since', 'content' => '1.4.0'), array('name' => 'param', 'content' => 'A string variable which is the first parameter.', 'types' => array('string'), 'variable' => '$var'), array('name' => 'param', 'content' => 'An array of user IDs.', 'types' => array('int[]'), 'variable' => '$ids'), array('name' => 'return', 'content' => 'The return type is random. (Not really.)', 'types' => array('mixed'))), get_post_meta($post->ID, '_wp-parser_tags', true));
}
示例13: live_blogs_for_entry_id
/**
* @param $entry_id
*
* @return LiveBlogging_LiveBlog|null
*/
public static function live_blogs_for_entry_id($entry_id)
{
foreach (wp_get_object_terms(array($entry_id), 'liveblog') as $liveblog_term) {
return new LiveBlogging_LiveBlog($liveblog_term);
}
return null;
}
示例14: edd_dwqa_categories_save_post_download
function edd_dwqa_categories_save_post_download($post_ID, $post, $update)
{
global $wpdb;
$bundle = get_post_meta($post_ID, '_edd_product_type', true);
if ($bundle == 'bundle') {
return true;
}
$checked_terms = wp_get_object_terms($post_ID, 'download_category', array('fields' => 'ids'));
if (is_array($checked_terms) && !empty($checked_terms)) {
foreach ($checked_terms as $category) {
//check if product category is dwqa category also
$term_taxonomy_id = $wpdb->get_results($wpdb->prepare("SELECT term_taxonomy_id FROM " . $wpdb->prefix . "term_taxonomy WHERE term_id = %d AND taxonomy = 'dwqa-question_category' ", $category));
if ($term_taxonomy_id > 0) {
$post_object['parent'] = $category;
} else {
$post_object['parent'] = 0;
}
$post_object = array();
$post_object['action'] = 'add-tag';
$tag = wp_insert_term($post->post_title, 'dwqa-question_category', $post_object);
if (!is_wp_error($tag)) {
$wpdb->query($wpdb->prepare("INSERT INTO " . $wpdb->prefix . "edd_dwqa_categories (id, dwqa_category_id, edd_product_id, edd_product_category_id) VALUES ('', %d, %d, '')", $tag['term_id'], $post_ID));
}
}
} else {
$post_object = array();
$post_object['action'] = 'add-tag';
$post_object['parent'] = 0;
$tag = wp_insert_term($post->post_title, 'dwqa-question_category', $post_object);
if (!is_wp_error($tag)) {
$wpdb->query($wpdb->prepare("INSERT INTO " . $wpdb->prefix . "edd_dwqa_categories (id, dwqa_category_id, edd_product_id, edd_product_category_id) VALUES ('', %d, %d, '')", $tag['term_id'], $post_ID));
}
}
return true;
}
示例15: __construct
public function __construct($post = null)
{
if (!empty($post) && ($post = get_post($post))) {
$this->id = $post->ID;
$this->date = get_the_time(__('Y/m/d g:i:s A', 'flamingo'), $this->id);
$this->subject = get_post_meta($post->ID, '_subject', true);
$this->from = get_post_meta($post->ID, '_from', true);
$this->from_name = get_post_meta($post->ID, '_from_name', true);
$this->from_email = get_post_meta($post->ID, '_from_email', true);
$this->fields = get_post_meta($post->ID, '_fields', true);
foreach ($this->fields as $key => $value) {
$meta_key = sanitize_key('_field_' . $key);
if (metadata_exists('post', $post->ID, $meta_key)) {
$value = get_post_meta($post->ID, $meta_key, true);
$this->fields[$key] = $value;
}
}
$this->meta = get_post_meta($post->ID, '_meta', true);
$this->akismet = get_post_meta($post->ID, '_akismet', true);
$terms = wp_get_object_terms($this->id, self::channel_taxonomy);
if (!empty($terms) && !is_wp_error($terms)) {
$this->channel = $terms[0]->slug;
}
if (self::spam_status == get_post_status($post)) {
$this->spam = true;
} else {
$this->spam = !empty($this->akismet['spam']);
}
}
}