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


PHP wp_set_post_terms函数代码示例

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


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

示例1: create_feedback

 public function create_feedback($params)
 {
     global $un_settings;
     if (isset($params['title']) && $params['title']) {
         $title = $params['title'];
     }
     $content = $params['description'];
     if (empty($params['title'])) {
         $title = substr($content, 0, 150) . (strlen($content) < 150 ? '' : "…");
     }
     $id = wp_insert_post(array('post_type' => FEEDBACK, 'post_title' => wp_kses(apply_filters('un_feedback_title', $title, $params), wp_kses_allowed_html()), 'post_content' => wp_kses(apply_filters('un_feedback_content', $content, $params), wp_kses_allowed_html()), 'post_status' => un_get_option(UN_PUBLISH_DIRECTLY) ? 'publish' : 'pending', 'post_author' => 0));
     $email = isset($params['email']) ? trim($params['email']) : '';
     if ($email) {
         add_post_meta($id, '_email', $email);
     }
     if (is_user_logged_in()) {
         add_post_meta($id, '_author', get_current_user_id());
     }
     if (isset($params['name']) && trim($params['name'])) {
         add_post_meta($id, '_name', wp_kses(trim($params['name']), wp_kses_allowed_html()));
     }
     wp_set_post_terms($id, $params['type'], FEEDBACK_TYPE);
     do_action('un_feedback_created', $id, $params);
     $this->send_admin_message($id, $params);
 }
开发者ID:congtrieu112,项目名称:anime,代码行数:25,代码来源:model.php

示例2: create

 /**
  * Create or edit a a project
  *
  * @param null|int $project_id
  * @return int
  */
 function create($project_id = 0, $posted = array())
 {
     $is_update = $project_id ? true : false;
     $data = array('post_title' => $posted['project_name'], 'post_content' => $posted['project_description'], 'post_type' => 'project', 'post_status' => 'publish');
     if ($is_update) {
         $data['ID'] = $project_id;
         $project_id = wp_update_post($data);
     } else {
         $project_id = wp_insert_post($data);
     }
     if ($project_id) {
         $this->insert_project_user_role($posted, $project_id);
         wp_set_post_terms($project_id, $posted['project_cat'], 'project_category', false);
         if ($is_update) {
             do_action('cpm_project_update', $project_id, $data);
         } else {
             update_post_meta($project_id, '_project_archive', 'no');
             update_post_meta($project_id, '_project_active', 'yes');
             $settings = $this->settings_user_permission();
             update_post_meta($project_id, '_settings', $settings);
             do_action('cpm_project_new', $project_id, $data);
         }
     }
     return $project_id;
 }
开发者ID:javalidigital,项目名称:multipla,代码行数:31,代码来源:project.php

示例3: save_new_episode

 public function save_new_episode($item, $show_slug)
 {
     $item_date = $item->get_date('Y-m-d H:i:s');
     $enclosure = $item->get_enclosure();
     $post = array('post_title' => $item->get_title(), 'post_date' => $item_date, 'post_content' => $item->get_description(), 'post_status' => 'publish', 'post_type' => Dipo_Podcast_Post_Type::POST_TYPE, 'tags_input' => $enclosure->get_keywords());
     $post_id = wp_insert_post($post);
     if (!empty($show_slug)) {
         $term_id = term_exists($show_slug, 'podcast_show');
         wp_set_post_terms($post_id, $term_id, 'podcast_show');
     }
     // save episodes data as metadata for post
     $subtitle = htmlspecialchars($this->get_subtitle($item));
     update_post_meta($post_id, '_dipo_subtitle', $subtitle);
     $summary = htmlspecialchars($this->get_summary($item));
     update_post_meta($post_id, '_dipo_summary', $summary);
     $explicit = htmlspecialchars(strtolower($this->get_explicit($item)));
     $possible_values = array('yes', 'no', 'clean');
     if (in_array($explicit, $possible_values)) {
         update_post_meta($post_id, '_dipo_explicit', $explicit);
     }
     $medialink = esc_url_raw($enclosure->get_link());
     $type = htmlspecialchars($enclosure->get_type());
     $duration = htmlspecialchars($enclosure->get_duration('hh:mm:ss'));
     $length = htmlspecialchars($enclosure->get_length());
     $mediafile = array('id' => 1, 'medialink' => $medialink, 'mediatype' => $type, 'duration' => $duration, 'filesize' => $length);
     update_post_meta($post_id, '_dipo_mediafile1', $mediafile);
     update_post_meta($post_id, '_dipo_max_mediafile_number', '1');
     $this->created_episodes++;
     return $post_id;
 }
开发者ID:ICFMovement,项目名称:dicentis,代码行数:30,代码来源:class-dipo-feed-import.php

示例4: error_log

 public static function error_log($post_title, $error, $tags = array())
 {
     $post_content = (is_string($error) ? $error : print_r($error, true)) . "\n\n";
     $backtrace = debug_backtrace();
     // remove calls to this function and template tags that call it
     foreach ($backtrace as $i => $call) {
         if ('voce_error_log' === $call['function'] || 'error_log' === $call['function']) {
             unset($backtrace[$i]);
         }
     }
     $post_content .= "<hr>\n";
     foreach ($backtrace as $call) {
         if (isset($call['file']) && isset($call['line'])) {
             $post_content .= sprintf("%s - (%s:%d)\n", $call['function'], $call['file'], $call['line']);
         } else {
             $post_content .= $call['function'] . "\n";
             break;
             // stop when we get to the function containing the voce_error_log() call
         }
     }
     $postarr = compact('post_title', 'post_content');
     $postarr = array_merge($postarr, array('post_type' => self::POST_TYPE, 'post_status' => 'publish', 'post_tag' => $tags));
     $log_id = wp_insert_post($postarr);
     wp_set_post_terms($log_id, $tags, self::TAXONOMY);
 }
开发者ID:gopinathshiva,项目名称:wordpress-vip-plugins,代码行数:25,代码来源:voce-error-logging.php

示例5: scoper_force_custom_taxonomy_filters

function scoper_force_custom_taxonomy_filters($post_id, $post)
{
    $post_type_obj = get_post_type_object($post->post_type);
    foreach ($post_type_obj->taxonomies as $taxonomy) {
        // if terms were selected, WP core already applied the filter and there is no need to apply default terms
        if (in_array($taxonomy, array('category', 'post_tag')) || did_action("pre_post_{$taxonomy}")) {
            continue;
        }
        // don't filter term selection for non-hierarchical taxonomies
        if (empty($GLOBALS['wp_taxonomies'][$taxonomy]->hierarchical)) {
            continue;
        }
        if ($taxonomy_obj = get_taxonomy($taxonomy)) {
            if (!empty($_POST['tax_input'][$taxonomy]) && is_array($_POST['tax_input'][$taxonomy]) && (reset($_POST['tax_input'][$taxonomy]) || count($_POST['tax_input'][$taxonomy]) > 1)) {
                // complication because (as of 3.0) WP always includes a zero-valued first array element
                $tags = $_POST['tax_input'][$taxonomy];
            } elseif ('auto-draft' != $post->post_status) {
                $tags = (array) get_option("default_{$taxonomy}");
            } else {
                $tags = array();
            }
            if ($tags) {
                if (!empty($_POST['tax_input']) && is_array($_POST['tax_input'][$taxonomy])) {
                    // array = hierarchical, string = non-hierarchical.
                    $tags = array_filter($tags);
                }
                if (current_user_can($taxonomy_obj->cap->assign_terms)) {
                    $tags = apply_filters("pre_post_{$taxonomy}", $tags);
                    $tags = apply_filters("{$taxonomy}_pre", $tags);
                    wp_set_post_terms($post_id, $tags, $taxonomy);
                }
            }
        }
    }
}
开发者ID:btj,项目名称:cscircles-wp-content,代码行数:35,代码来源:filters-admin-save_rs.php

示例6: postStoreProcess

 public function postStoreProcess($table, $newTags = array(), $replace = true)
 {
     return false;
     if (!empty($table->newTags) && empty($newTags)) {
         $newTags = $table->newTags;
     }
     // If existing row, check to see if tags have changed.
     $newTable = clone $table;
     $newTable->reset();
     $key = $newTable->getKeyName();
     $typeAlias = $this->typeAlias;
     $result = false;
     if ($this->tagsChanged || !empty($newTags) && $newTags[0] != '') {
         $taxonomy_obj = get_taxonomy($typeAlias);
         if (is_array($newTags)) {
             // array = hierarchical, string = non-hierarchical.
             $newTags = array_filter($newTags);
         }
         if (current_user_can($taxonomy_obj->cap->assign_terms)) {
             $result = wp_set_post_terms($table->id, $newTags, $typeAlias);
             if (is_array($result) && count($result) > 0) {
                 $result = true;
             } elseif (is_object($result)) {
                 $result = false;
             }
         }
     }
     return $result;
 }
开发者ID:vanie3,项目名称:appland,代码行数:29,代码来源:tags.php

示例7: post_add_tax

 function post_add_tax($value, $object, $field_name)
 {
     //var_dump( $value );
     foreach ($value as $term => $tax) {
         wp_set_post_terms($object->ID, array(intval($term)), $tax, true);
     }
 }
开发者ID:KodkodGates,项目名称:angularjs-for-wordpress,代码行数:7,代码来源:plugin.php

示例8: 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

示例9: add_post_to_cat

function add_post_to_cat()
{
    // Get the Post ID
    if (isset($_POST['post_id']) && !empty($_POST['post_id'])) {
        $post_id = esc_html($_POST['post_id']);
    } else {
        echo json_encode(array('success' => false, 'reason' => 'No Post ID.'));
        exit;
    }
    // Get the Category
    if (isset($_POST['cat_id']) && !empty($_POST['cat_id'])) {
        $cat_id = esc_html($_POST['cat_id']);
    } else {
        echo json_encode(array('success' => false, 'reason' => 'No Cat ID.'));
        exit;
    }
    // Check if Post is already in this category
    if (has_term($cat_id, 'bookmark-category', $post_id)) {
        echo json_encode(array('success' => true, 'reason' => 'duplicate'));
        exit;
    }
    // Add Post to Bookmark Category
    $did_add_cat = wp_set_post_terms($post_id, $cat_id, 'bookmark-category', true);
    if ($did_add_cat) {
        echo json_encode(array('success' => true, 'reason' => 'inserted'));
    } else {
        echo json_encode(array('success' => false, 'reason' => "Couldn't add cat."));
    }
    exit;
}
开发者ID:ryan-frankel,项目名称:nerdmash,代码行数:30,代码来源:ajax-add-cat-to-post.php

示例10: post

 public function post()
 {
     if (isset($_POST['review_id'])) {
         update_post_meta($_POST['review_id'], 'color', $_POST['color']);
         update_post_meta($_POST['review_id'], 'espuma', $_POST['espuma']);
         update_post_meta($_POST['review_id'], 'alcohol', $_POST['alcohol']);
         update_post_meta($_POST['review_id'], 'cuerpo', $_POST['cuerpo']);
         update_post_meta($_POST['review_id'], 'final', $_POST['final']);
         update_post_meta($_POST['review_id'], 'amargor', $_POST['amargor']);
         update_post_meta($_POST['review_id'], 'rating', $_POST['rating']);
         $cerveza_id = get_post_meta($_POST['review_id'], 'cerveza_id', true);
         $flavors = $_POST['tax_input']['flavor_of_beer'];
         $aromas = $_POST['tax_input']['aroma_of_beer'];
         wp_set_post_terms($_POST['review_id'], $flavors, 'flavor_of_beer');
         wp_set_post_terms($_POST['review_id'], $aromas, 'aroma_of_beer');
         global $wpdb;
         $sql = 'SELECT * FROM nwm_loc_hielera ';
         $sql .= 'WHERE beer=' . $cerveza_id . ' ';
         $sql .= 'AND user=' . get_current_user_id();
         if ($wpdb->get_row($sql) == null) {
             $newCoolerRow = array('user' => get_current_user_id(), 'beer' => $cerveza_id, 'review' => 1, 'rate' => 1, 'forlater' => 0, 'favorite' => 0, 'status' => 'Review');
             $wpdb->insert('nwm_loc_hielera', $newCoolerRow);
         } else {
             $updateCoolerRow = array('status' => 'Review', 'review' => 1);
             $wpdb->update('nwm_loc_hielera', $updateCoolerRow, array('user' => get_current_user_id(), 'beer' => $cerveza_id));
         }
         $wpdb->insert('nwm_loc_hielera', array('user' => get_current_user_id(), 'beer' => $cerveza_id));
         $wpdb->update('nwm_loc_hielera', array('status' => 'Reviewed', 'review' => 1, 'rate' => 1), array('user' => get_current_user_id(), 'beer' => $cerveza_id));
     }
 }
开发者ID:mauricioabisay,项目名称:nwm-loc,代码行数:30,代码来源:class-plugin-name-public.php

示例11: handle_question_editing

 function handle_question_editing()
 {
     global $wpdb;
     if (!wp_verify_nonce($_POST['_wpnonce'], 'qa_edit')) {
         wp_die(__('Are you sure you want to do that?', QA_TEXTDOMAIN));
     }
     $question_id = (int) $_POST['question_id'];
     if (!$question_id && !current_user_can('publish_questions')) {
         wp_die(__('You are not allowed to post questions', QA_TEXTDOMAIN));
     }
     $question = array('post_title' => trim($_POST['question_title']), 'post_content' => trim($_POST['question_content']));
     if (empty($question['post_title']) || empty($question['post_content'])) {
         wp_die(__('Questions must have both a title and a body.', QA_TEXTDOMAIN));
     }
     // Check for duplicates
     if (!$question_id) {
         $dup_id = $wpdb->get_var($wpdb->prepare("\n\t\t\t\tSELECT ID\n\t\t\t\tFROM {$wpdb->posts}\n\t\t\t\tWHERE post_type = 'question'\n\t\t\t\tAND post_status = 'publish'\n\t\t\t\tAND (post_title = %s OR post_content = %s)\n\t\t\t\tLIMIT 1\n\t\t\t", $question['post_title'], $question['post_content']));
         if ($dup_id) {
             wp_die(sprintf(__('It seems that question was <a href="%s">already asked</a>.', QA_TEXTDOMAIN), qa_get_url('single', $dup_id)));
         }
     }
     $question_id = $this->_insert_post($question_id, $question, array('post_type' => 'question', 'comment_status' => 'open'));
     wp_set_post_terms($question_id, $_POST['question_tags'], 'question_tag');
     return qa_get_url('single', $question_id);
 }
开发者ID:rgrp,项目名称:wordpress-qa,代码行数:25,代码来源:edit.php

示例12: wdm_modified_bid_place

function wdm_modified_bid_place($args)
{
    global $wpdb;
    $wpdb->show_errors();
    $wpdb->insert($wpdb->prefix . 'wdm_bidders', array('name' => $args['orig_name'], 'email' => $args['orig_email'], 'auction_id' => $args['auc_id'], 'bid' => $args['orig_bid'], 'date' => date("Y-m-d H:i:s", time())), array('%s', '%s', '%d', '%f', '%s'));
    update_post_meta($args['auc_id'], 'wdm_previous_bid_value', $args['mod_bid']);
    //store bid value of the most recent bidder
    $place_bid = $wpdb->insert($wpdb->prefix . 'wdm_bidders', array('name' => $args['mod_name'], 'email' => $args['mod_email'], 'auction_id' => $args['auc_id'], 'bid' => $args['mod_bid'], 'date' => date("Y-m-d H:i:s", time())), array('%s', '%s', '%d', '%f', '%s'));
    if ($place_bid) {
        $c_code = substr(get_option('wdm_currency'), -3);
        $char = $args['site_char'];
        $ret_url = $args['auc_url'];
        $adm_email = get_option("wdm_auction_email");
        if ($args['email_type'] === 'winner') {
            update_post_meta($args['auc_id'], 'wdm_listing_ends', date("Y-m-d H:i:s", time()));
            $check_term = term_exists('expired', 'auction-status');
            wp_set_post_terms($args['auc_id'], $check_term["term_id"], 'auction-status');
            update_post_meta($args['auc_id'], 'email_sent_imd', 'sent_imd');
            $args['stat'] = "Won";
        } else {
            $args['stat'] = "Placed";
        }
        $args['adm_email'] = $adm_email;
        $args['ret_url'] = $ret_url;
        $args['type'] = 'proxy';
        echo json_encode($args);
    }
}
开发者ID:tvolmari,项目名称:hammydowns,代码行数:28,代码来源:ua-proxy-bidding.php

示例13: cjtheme_insert_question

function cjtheme_insert_question()
{
    global $wpdb;
    $errors = null;
    parse_str($_POST['data'], $postdata);
    if ($postdata['question'] == '') {
        $errors[] = __('Please enter some content to ask.', 'cjtheme');
    }
    if ($postdata['category'] == '') {
        $errors[] = __('You must select a category for this question.', 'cjtheme');
    }
    if (!is_null($errors)) {
        $return['errors'] = cjtheme_show_message('error', implode('<br>', $errors));
    } else {
        // $post_title = cjtheme_trim_text($postdata['question'], '60');
        $post_title = $postdata['question'];
        $question_data = array('post_title' => $post_title, 'post_name' => sanitize_title($post_title), 'post_content' => esc_textarea($postdata['question']), 'post_type' => 'questions', 'post_status' => 'publish');
        $post_id = wp_insert_post($question_data);
        wp_set_post_terms($post_id, $postdata['category'], 'qna_type');
        //$return['success'] = $postdata['current_url'].'#question-'.$post_id;
        $return['success'] = get_permalink($post_id);
    }
    echo json_encode($return);
    die;
}
开发者ID:praveen-thayikkattil,项目名称:cartoq-theme,代码行数:25,代码来源:ajax-qna.php

示例14: set_terms

 /**
  * Wrapper for terms setting to post.
  *
  * @param array  $terms    List of terms to set.
  * @param string $taxonomy Name of taxonomy to set terms to.
  * @param bool   $append   When true post may have multiple same instances.
  *
  * @return bool Success.
  */
 public function set_terms(array $terms, $taxonomy, $append = false)
 {
     $result = wp_set_post_terms($this->_post_id, $terms, $taxonomy, $append);
     if (is_wp_error($result)) {
         return false;
     }
     return $result;
 }
开发者ID:washingtonstateuniversity,项目名称:WSUWP2-CAHNRS-Plugin-Collection,代码行数:17,代码来源:taxonomy.php

示例15: copy_tags_from_old_to_new

function copy_tags_from_old_to_new($old_id, $new_id)
{
    $old_terms = wp_get_post_terms($old_id, 'post_tag');
    $old_term_ids = array_map(function ($term) {
        return $term->term_id;
    }, $old_terms);
    wp_set_post_terms($new_id, $old_term_ids, 'post_tag', true);
}
开发者ID:nathanielks,项目名称:wp-podcast-post-type,代码行数:8,代码来源:functions.php


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