当前位置: 首页>>代码示例>>PHP>>正文


PHP wp_set_object_terms函数代码示例

本文整理汇总了PHP中wp_set_object_terms函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_set_object_terms函数的具体用法?PHP wp_set_object_terms怎么用?PHP wp_set_object_terms使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了wp_set_object_terms函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: sell_media_set_default_terms

/**
 * Set Default Terms
 * Used in attachment-functions.php
 *
 * @since 0.1
 */
function sell_media_set_default_terms($post_id, $post = null, $term_ids = null)
{
    if (is_null($post)) {
        $post_type = get_post_type($post_id);
    } else {
        $post_type = $post->post_type;
        $post_status = $post->post_status;
    }
    if (empty($post_status)) {
        return;
    }
    if (empty($term_ids) || $term_ids === true) {
        $term_ids = sell_media_get_default_terms();
    }
    $taxonomy = 'licenses';
    $default_terms = array();
    foreach ($term_ids as $term_id) {
        $tmp_term_id = get_term_by('id', $term_id, $taxonomy);
        if ($tmp_term_id) {
            $default_terms[] = (int) $tmp_term_id->term_id;
            $default_terms[] = (int) $tmp_term_id->parent;
        }
    }
    $defaults = array($taxonomy => $default_terms);
    $taxonomies = get_object_taxonomies($post_type);
    foreach ((array) $taxonomies as $taxonomy) {
        $terms = wp_get_post_terms($post_id, $taxonomy);
        if (empty($terms) && array_key_exists($taxonomy, $defaults)) {
            wp_set_object_terms($post_id, $defaults[$taxonomy], $taxonomy);
        }
    }
}
开发者ID:rickalday,项目名称:Sell-Media,代码行数:38,代码来源:term-meta.php

示例2: p2_at_names

function p2_at_names($content)
{
    global $post, $comment;
    $name_map = p2_get_at_name_map();
    // get users user_login and display_name map
    $content_original = $content;
    // save content before @names are found
    foreach ($name_map as $name => $values) {
        //loop and...
        $content = str_ireplace($name, $values['replacement'], $content);
        // Change case to that in $name_map
        $content = strtr($content, $name, $name);
        // Replaces keys with values longest to shortest, without re-replacing pieces it's already done
        if ($content != $content_original) {
            // if the content has changed, an @name has been found.
            $users_to_add[] = get_usermeta($name_map[$name]['id'], 'user_login');
        }
        // add that user to an array.
        $content_original = $content;
    }
    if (is_array($users_to_add)) {
        $cache_data = implode($users_to_add);
    }
    // if we've got an array, make it a comma delimited string
    if (isset($cache_data) && $cache_data != wp_cache_get('mentions', $post->ID)) {
        wp_set_object_terms($post->ID, $users_to_add, 'mentions', true);
        // tag the post.
        wp_cache_set('mentions', $cache_data, $post->ID);
    }
    return $content;
}
开发者ID:rmccue,项目名称:wordpress-unit-tests,代码行数:31,代码来源:functions.php

示例3: wpp_edit_save_promotion

function wpp_edit_save_promotion($id, $title, $content, $category, $attach_id, $promoStart, $promoEnd, $nonce)
{
    //sanitize data
    $id = sanitize_text_field($id);
    $title = sanitize_text_field($title);
    $content = sanitize_text_field($content);
    $category = sanitize_text_field($category);
    $attachid = sanitize_text_field($attach_id);
    $promoStart = sanitize_text_field($promoStart);
    $promoEnd = sanitize_text_field($promoEnd);
    //make sure this post belongs to the user
    $user_id = get_current_user_id();
    $query = new WP_Query(array('post_type' => promo, 'p' => $id, 'posts_per_page' => '-1', 'post_status' => array('publish', 'pending', 'draft', 'trash'), 'author' => $user_id));
    if ($query->found_posts === 0) {
        wp_die();
    }
    wp_reset_query();
    $data = array();
    $post_information = array('ID' => $id, 'post_title' => $title, 'post_content' => $content, 'post-type' => 'promotion', 'post_status' => 'pending');
    $post_id = wp_update_post($post_information);
    //set object terms
    wp_set_object_terms($post_id, $category, 'promotion_category', true);
    update_post_meta($post_id, 'wpp_promo_start', $promoStart);
    update_post_meta($post_id, 'wpp_promo_end', $promoEnd);
    update_post_meta($post_id, 'wpp_promo_logged', 'not_logged');
    if (!is_wp_error($attach_id)) {
        //and if you want to set that image as Post  then use
        set_post_thumbnail($post_id, $attach_id);
    }
    $data['id'] = $post_id;
    $data['start'] = wpp_date_to_unix($promoStart);
    $data['end'] = wpp_date_to_unix($promoEnd);
    wpp_schedule_promotion_events($data);
}
开发者ID:saowapan,项目名称:wp-promotions,代码行数:34,代码来源:shortcode-functions.php

示例4: add_new_category

function add_new_category()
{
    if (is_user_logged_in()) {
        if (isset($_POST['cat_name']) && !empty($_POST['cat_name']) && isset($_POST['parent_id']) && !empty($_POST['parent_id'])) {
            $cat_name = esc_html($_POST['cat_name']);
            $parent_id = esc_html($_POST['parent_id']);
            $new_cat_args = array($cat_name, 'bookmark-category');
            if ($parent_id == -1) {
                // Add Term to Bookmark Category
                $new_category = wp_insert_term($cat_name, 'bookmark-category');
            } else {
                // Add Term to Bookmark Category
                $new_category = wp_insert_term($cat_name, 'bookmark-category', array('parent' => $parent_id));
            }
            if (!is_wp_error($new_category)) {
                $term = get_term_by('id', $new_category['term_id'], 'bookmark-category');
                // Add Term to User
                wp_set_object_terms($current_user->ID, array($term->slug), 'bookmark-category', true);
                $returner = array('success' => true, 'cat_id' => $new_category['term_id'], 'cat_slug' => $term->slug, 'cat_link' => get_term_link($term, 'bookmark-category'));
            } else {
                $returner = array('success' => false, 'reason' => 'WP Error on term creation.');
            }
        } else {
            $returner = array('success' => false, 'reason' => 'Post values not set.');
        }
    } else {
        $returner = array('success' => false, 'reason' => 'User not logged in.');
    }
    echo json_encode($returner);
    exit;
}
开发者ID:ryan-frankel,项目名称:nerdmash,代码行数:31,代码来源:add_new_category.php

示例5: set_terms

 public function set_terms($key, $terms)
 {
     foreach ($terms as $term_data) {
         $term = new Term($term_data->name, $term_data->taxonomy);
         wp_set_object_terms($this->id, intval($term->id), $term_data->taxonomy, true);
     }
 }
开发者ID:oligoform,项目名称:mesh,代码行数:7,代码来源:mesh-post.php

示例6: migrate

 /**
  * Migrate meta values to taxonomy terms. Delete meta after import
  *
  * ## OPTIONS
  *
  * <meta-key>
  * : Meta key to convert
  *
  * <taxonomy-slug>
  * : Taxonomy to move values into
  *
  * [--<field>=<value>]
  * : One or more args to pass to WP_Query.
  *
  * ## EXAMPLES
  *
  *     wp mtt migrate meta_key taxonomy_slug
  *     wp mtt migrate meta_key taxonomy_slug --posts_per_page=200 --paged=2
  *
  */
 function migrate($args, $assoc_args)
 {
     list($meta_key, $taxonomy) = $args;
     if (!($taxonomy_object = get_taxonomy($taxonomy))) {
         WP_CLI::error(sprintf("The taxonomy '%s' doesn't exist", $taxonomy));
     }
     $defaults = array('post_type' => $taxonomy_object->object_type, 'posts_per_page' => -1, 'post_status' => 'any');
     $query_args = array_merge($defaults, $assoc_args);
     $query = new WP_Query($query_args);
     // summary
     WP_CLI::log(sprintf("---\nPer page: %d \nPage: %d \nTotal pages: %d\n---", $query_args['posts_per_page'], isset($query_args['paged']) ? $query_args['paged'] : 1, $query->max_num_pages));
     while ($query->have_posts()) {
         $query->the_post();
         $id = get_the_id();
         // get meta
         $metas = get_post_meta($id, $meta_key);
         // create term
         if (!$metas) {
             WP_CLI::log(WP_CLI::colorize("%c[{$id}]%n No meta, skipped"));
         } else {
             if (!is_wp_error(wp_set_object_terms($id, $metas, $taxonomy, true))) {
                 WP_CLI::log(WP_CLI::colorize("%g[{$id}]%n Migrated: " . implode(', ', $metas)));
                 // clean meta
                 delete_post_meta($id, $meta_key);
             } else {
                 WP_CLI::log(WP_CLI::colorize("%r[{$id}]%n Error: Could not set terms for post"));
             }
         }
     }
 }
开发者ID:trepmal,项目名称:wp-cli-meta-to-term,代码行数:50,代码来源:meta-to-term-cli.php

示例7: save

 public static function save($post_id)
 {
     if (isset($_POST['_unit'])) {
         update_post_meta($post_id, '_unit', sanitize_text_field($_POST['_unit']));
     }
     if (isset($_POST['_unit_base'])) {
         update_post_meta($post_id, '_unit_base', $_POST['_unit_base'] === '' ? '' : wc_format_decimal($_POST['_unit_base']));
     }
     if (isset($_POST['_unit_price_regular'])) {
         update_post_meta($post_id, '_unit_price_regular', $_POST['_unit_price_regular'] === '' ? '' : wc_format_decimal($_POST['_unit_price_regular']));
         update_post_meta($post_id, '_unit_price', $_POST['_unit_price_regular'] === '' ? '' : wc_format_decimal($_POST['_unit_price_regular']));
     }
     if (isset($_POST['_unit_price_sale'])) {
         update_post_meta($post_id, '_unit_price_sale', '');
         // Update Sale Price only if is on sale (Cron?!)
         if (get_post_meta($post_id, '_price', true) != $_POST['_regular_price'] && $_POST['_unit_price_sale'] !== '') {
             update_post_meta($post_id, '_unit_price_sale', $_POST['_unit_price_sale'] === '' ? '' : wc_format_decimal($_POST['_unit_price_sale']));
             update_post_meta($post_id, '_unit_price', $_POST['_unit_price_sale'] === '' ? '' : wc_format_decimal($_POST['_unit_price_sale']));
         }
     }
     if (isset($_POST['_mini_desc'])) {
         update_post_meta($post_id, '_mini_desc', esc_html($_POST['_mini_desc']));
     }
     if (isset($_POST['delivery_time']) && !is_numeric($_POST['delivery_time'])) {
         wp_set_post_terms($post_id, sanitize_text_field($_POST['delivery_time']), 'product_delivery_time');
     } else {
         wp_set_object_terms($post_id, absint($_POST['delivery_time']), 'product_delivery_time');
     }
 }
开发者ID:radscheit,项目名称:unicorn,代码行数:29,代码来源:class-wc-gzd-meta-box-product-data.php

示例8: categorize

 private function categorize($post_id, $categories_str)
 {
     $categories_arr = explode(',', $categories_str);
     foreach ($categories_arr as $category) {
         $categories_par = explode('>', $category);
         if (!isset($categories_par[0], $categories_par[1])) {
             $this->err($category, $post_id);
         }
         $categories_par[0] = trim($categories_par[0]);
         $categories_par[1] = trim($categories_par[1]);
         $parent_term = term_exists($categories_par[0], 'venture_categories');
         if (!$parent_term) {
             $parent_term = wp_insert_term($categories_par[0], 'venture_categories');
         }
         $parent_term_id = intval($parent_term['term_id']);
         $term = term_exists($categories_par[1], 'venture_categories', $parent_term_id);
         if (!$term) {
             $term = wp_insert_term($categories_par[1], 'venture_categories', array('parent' => $parent_term_id));
         }
         if (is_wp_error($term)) {
             $this->err($category, $post_id);
         }
         $term_id = intval($term['term_id']);
         wp_set_object_terms($post_id, $parent_term_id, 'venture_categories', true);
         wp_set_object_terms($post_id, $term_id, 'venture_categories', true);
     }
 }
开发者ID:johnleesw,项目名称:mustardseedwp,代码行数:27,代码来源:Class_Import_Page.php

示例9: sui_form_shortcode

function sui_form_shortcode()
{
    if (!is_user_logged_in()) {
        return '<p>You need to be logged in to submit an image.</p>';
    }
    global $current_user;
    if (isset($_POST['sui_upload_image_form_submitted']) && wp_verify_nonce($_POST['sui_upload_image_form_submitted'], 'sui_upload_image_form')) {
        $result = sui_parse_file_errors($_FILES['sui_image_file'], $_POST['sui_image_caption']);
        if ($result['error']) {
            echo '<p>ERROR: ' . $result['error'] . '</p>';
        } else {
            $user_image_data = array('post_title' => $result['caption'], 'post_status' => 'pending', 'post_author' => $current_user->ID, 'post_type' => 'user_images');
            if ($post_id = wp_insert_post($user_image_data)) {
                sui_process_image('sui_image_file', $post_id, $result['caption']);
                wp_set_object_terms($post_id, (int) $_POST['sui_image_category'], 'sui_image_category');
            }
        }
    }
    if (isset($_POST['sui_form_delete_submitted']) && wp_verify_nonce($_POST['sui_form_delete_submitted'], 'sui_form_delete')) {
        if (isset($_POST['sui_image_delete_id'])) {
            if ($user_images_deleted = sui_delete_user_images($_POST['sui_image_delete_id'])) {
                echo '<p>' . $user_images_deleted . ' images(s) deleted!</p>';
            }
        }
    }
    echo sui_get_upload_image_form($sui_image_caption = $_POST['sui_image_caption'], $sui_image_category = $_POST['sui_image_category']);
    if ($user_images_table = sui_get_user_images_table($current_user->ID)) {
        echo $user_images_table;
    }
}
开发者ID:iwan14102065,项目名称:yes_wptheme,代码行数:30,代码来源:avatar-func.php

示例10: maybe_restore_object_terms

 function maybe_restore_object_terms($object_id, $terms, $tt_ids, $taxonomy, $append, $old_tt_ids)
 {
     if (isset($this->scheduled_term_restoration[$object_id][$taxonomy])) {
         wp_set_object_terms($object_id, $this->scheduled_term_restoration[$object_id][$taxonomy], $taxonomy);
         unset($this->scheduled_term_restoration[$object_id][$taxonomy]);
     }
 }
开发者ID:Netsoro,项目名称:gdnlteamgroup,代码行数:7,代码来源:xmlrpc_rs.php

示例11: save

 public function save($eventObj)
 {
     global $wpdb;
     //Check to see if this event has actually been added.
     $foundId = $wpdb->get_results("SELECT post_id FROM {$wpdb->postmeta} WHERE meta_key='_EventBriteId' AND meta_value={$eventObj->ID}");
     $post_id = $foundId[0]->post_id;
     if ($post_id) {
         wp_update_post(array('ID' => $foundId, 'post_title' => $eventObj->post_title, 'post_content' => $eventObj->post_content, 'post_date' => $eventObj->post_date, 'post_author' => 1));
     } else {
         $post_id = wp_insert_post(array('post_type' => 'tribe_events', 'post_title' => $eventObj->post_title, 'post_content' => $eventObj->post_content, 'post_status' => 'publish', 'post_date' => $eventObj->post_date, 'post_author' => 1));
         //Static meta
         update_post_meta($post_id, '_EventShowTickets', 'yes');
         update_post_meta($post_id, '_EventVenueID', 304);
         //hardcoded to ID of Amazing Things venue post
         update_post_meta($post_id, '_EventRegister', 'yes');
         update_post_meta($post_id, '_EventOrigin', 'eventbrite-tickets');
         //only want to run this once.
         if ($eventObj->logo_url) {
             $this->transfer_image($post_id, $eventObj);
         }
     }
     update_post_meta($post_id, '_EventStartDate', date_format($eventObj->start, 'Y-m-d H:i:s'));
     update_post_meta($post_id, '_EventEndDate', date_format($eventObj->end, 'Y-m-d H:i:s'));
     update_post_meta($post_id, '_EventBriteId', $eventObj->ID);
     update_post_meta($post_id, '_EventURL', esc_url($eventObj->url));
     if ($eventObj->category) {
         wp_set_object_terms($post_id, $eventObj->category, 'tribe_events_cat');
     }
     if ($eventObj->tags) {
         wp_set_object_terms($post_id, $eventObj->tags, 'post_tag', false);
     }
     if ($eventObj->format) {
         wp_set_object_terms($post_id, $eventObj->format, 'event-type');
     }
 }
开发者ID:CodeProKid,项目名称:eventbrite-integration,代码行数:35,代码来源:eventbrite-api.php

示例12: save

 public function save($post_id)
 {
     if (!isset($_POST['fpr_metabox_nonce_field'])) {
         return $post_id;
     }
     $nonce = sanitize_text_field($_POST['fpr_metabox_nonce_field']);
     if (!wp_verify_nonce($nonce, 'ferina_product_retail_metabox_nonce')) {
         return $post_id;
     }
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return $post_id;
     }
     if ('retail-product' == $_POST['post_type']) {
         if (!current_user_can('edit_page', $post_id)) {
             return $post_id;
         }
     } else {
         if (!current_user_can('edit_post', $post_id)) {
             return $post_id;
         }
     }
     $ferina_sku = sanitize_text_field($_POST['ferina_sku']);
     $ferina_prod_desc = $_POST['ferina_product_description'];
     $prices = sanitize_text_field($_POST['ferina_product_prices']);
     $productstyle = sanitize_text_field($_POST['ferina_style']);
     $ferina_product_images = $_POST['ferina_product_images'];
     $productstyle = $productstyle > 0 ? get_term($productstyle, 'style')->slug : NULL;
     update_post_meta($post_id, '_ferina_sku_product', $ferina_sku);
     update_post_meta($post_id, '_ferina_description_product', $ferina_prod_desc);
     update_post_meta($post_id, '_ferina_product_prices', $prices);
     update_post_meta($post_id, '_ferina_product_images', serialize($ferina_product_images));
     wp_set_object_terms($post_id, $productstyle, 'style');
 }
开发者ID:arieyayank,项目名称:ferina-themes,代码行数:33,代码来源:metabox.php

示例13: mark_posts_misc_functions

/**
 * Misc functions
 *
 * @since     1.0.0
 * @updated   1.0.8
 */
function mark_posts_misc_functions()
{
    // mark all posts
    if ($_SERVER["REQUEST_METHOD"] == "GET" && isset($_GET['mark-all-posts-term-id'])) {
        $term_id = $_GET['mark-all-posts-term-id'];
        /* TODO:: SECURITY */
        // set color only for selected post types
        $get_mark_posts_settings = get_option('mark_posts_settings');
        foreach ($get_mark_posts_settings['mark_posts_posttypes'] as $post_type) {
            $args = array('posts_per_page' => -1, 'post_type' => $post_type);
            // get all posts
            $all_posts = get_posts($args);
            foreach ($all_posts as $post) {
                // Sanitize the user input.
                $mydata = sanitize_text_field($term_id);
                $myterm = get_term($term_id, 'marker');
                // Update the meta field.
                update_post_meta($post->ID, 'mark_posts_term_id', $mydata);
                // Update taxonomy count
                wp_set_object_terms($post->ID, $myterm->name, 'marker');
            }
        }
        echo mark_posts_display_settings_updated();
    }
}
开发者ID:flymke,项目名称:mark-posts,代码行数:31,代码来源:admin.php

示例14: ph_migrate_post_category_handler

function ph_migrate_post_category_handler($post, $fields)
{
    $metas = array();
    foreach ($fields as $key => $value) {
        $prop = substr($key, strlen('categories:'));
        $metas[$prop] = $value;
    }
    $ids = $metas['ids'];
    if (isset($metas['taxonomy'])) {
        $taxonomies = $metas['taxonomy'];
    } else {
        $taxonomies = 'category';
    }
    if (!is_array($ids)) {
        $ids = array($ids);
        $taxonomies = array($taxonomies);
    } else {
        if (!is_array($taxonomies)) {
            $taxonomies = array($taxonomies);
        }
        while (count($ids) > count($taxonomies)) {
            $taxonomies[] = $taxonomies[0];
        }
    }
    $copy = array();
    for ($i = 0; $i < count($ids); $i++) {
        if (!isset($copy[$taxonomies[$i]]) || !in_array($ids[$i], $copy[$taxonomies[$i]])) {
            $copy[$taxonomies[$i]][] = $ids[$i];
        }
    }
    foreach ($copy as $taxonomy => $ids) {
        wp_set_object_terms($post['ID'], $ids, $taxonomy, false);
    }
}
开发者ID:palasthotel,项目名称:wp_migrate,代码行数:34,代码来源:post_category_field_handler.php

示例15: taxonomy

 /**
  *
  * Assigns random terms to all posts in a taxonomy.
  *
  * By default all objects of the 'post' post type will be randomized, use the
  * --post_type flag to target pages or a custom post type. Use the --include 
  * and --exclude flags to filter or ignore specific object IDs and the --before
  * and --after flags to specify a date range. Also, optionally pass --terms as
  * a list of terms you want to use for the randomization. If terms exist in the
  * target taxonomy, those terms will be used. If not, a string of 6 words 
  * generated randomly will be used for the randomization.
  * 
  * ## Options
  *
  * <taxonomy>
  * : The taxonomy that should get randomized
  *
  * ## Exmples
  *
  *     wp randomize category
  *     
  * @synopsis <taxonomy> [--include=<bar>] [--exclude=<foo>] [--post_type=<foo>] 
  * [--before=<bar>] [--after=<date>] [--terms=<terms>]
  * 
  **/
 public function taxonomy($args, $assoc_args)
 {
     $taxonomy = $args[0];
     $get_posts = $this->get_specified_posts($assoc_args);
     $message = $get_posts['message'];
     $posts = $get_posts['posts'];
     $args = $get_posts['args'];
     $preamble = "Will assign random {$taxonomy} terms";
     print_r("{$preamble} {$message}.\n");
     if (isset($assoc_args['terms'])) {
         $terms = explode(',', $assoc_args['terms']);
         \WP_CLI::log('Using terms ' . $assoc_args['terms']);
     } else {
         \WP_CLI::log('Gathering and processing random terms.');
         $terms = $this->get_random_terms();
         \WP_CLI::log('No term list given, using random terms.');
     }
     foreach ($posts as $p) {
         $index = array_rand($terms);
         $term = $terms[$index];
         \WP_CLI::log("Assigning {$term} to taxonomy {$taxonomy} for {$p->post_type} {$p->ID}");
         if (!term_exists($term, $taxonomy)) {
             wp_insert_term($term, $taxonomy);
         }
         wp_set_object_terms($p->ID, $term, $taxonomy, $append = false);
     }
 }
开发者ID:athaller,项目名称:cfpb-wp-cli,代码行数:52,代码来源:randomize.php


注:本文中的wp_set_object_terms函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。