本文整理汇总了PHP中wp_insert_term函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_insert_term函数的具体用法?PHP wp_insert_term怎么用?PHP wp_insert_term使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_insert_term函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: check_recipe_taxonomies
/**
* Check if we have recipe taxonomies
*/
public function check_recipe_taxonomies()
{
$taxonomies = $this->get();
if (count($taxonomies) == 0) {
$taxonomies = $this->add_taxonomy_to_array($taxonomies, 'ingredient', __('Ingredients', 'wp-ultimate-recipe'), __('Ingredient', 'wp-ultimate-recipe'));
$taxonomies = $this->add_taxonomy_to_array($taxonomies, 'course', __('Courses', 'wp-ultimate-recipe'), __('Course', 'wp-ultimate-recipe'));
$taxonomies = $this->add_taxonomy_to_array($taxonomies, 'cuisine', __('Cuisines', 'wp-ultimate-recipe'), __('Cuisine', 'wp-ultimate-recipe'));
$this->update($taxonomies);
update_option('wpurp_flush', '1');
wp_insert_term(__('Breakfast', 'wp-ultimate-recipe'), 'course');
wp_insert_term(__('Appetizer', 'wp-ultimate-recipe'), 'course');
wp_insert_term(__('Soup', 'wp-ultimate-recipe'), 'course');
wp_insert_term(__('Main Course', 'wp-ultimate-recipe'), 'course');
wp_insert_term(__('Side Dish', 'wp-ultimate-recipe'), 'course');
wp_insert_term(__('Salad', 'wp-ultimate-recipe'), 'course');
wp_insert_term(__('Dessert', 'wp-ultimate-recipe'), 'course');
wp_insert_term(__('Snack', 'wp-ultimate-recipe'), 'course');
wp_insert_term(__('Drinks', 'wp-ultimate-recipe'), 'course');
wp_insert_term(__('French', 'wp-ultimate-recipe'), 'cuisine');
wp_insert_term(__('Italian', 'wp-ultimate-recipe'), 'cuisine');
wp_insert_term(__('Mediterranean', 'wp-ultimate-recipe'), 'cuisine');
wp_insert_term(__('Indian', 'wp-ultimate-recipe'), 'cuisine');
wp_insert_term(__('Chinese', 'wp-ultimate-recipe'), 'cuisine');
wp_insert_term(__('Japanese', 'wp-ultimate-recipe'), 'cuisine');
wp_insert_term(__('American', 'wp-ultimate-recipe'), 'cuisine');
wp_insert_term(__('Mexican', 'wp-ultimate-recipe'), 'cuisine');
}
}
示例2: add_source_default
public static function add_source_default()
{
global $wpdb;
if (empty(self::$source_list)) {
return false;
}
foreach (self::$source_list as $source) {
if (isset($source['name'])) {
$term = get_term_by('name', $source['name'], 'dln_source_cat');
if (empty($term)) {
$term = wp_insert_term(esc_sql($source['name']), 'dln_source_cat');
}
if (!empty($term->term_id) && isset($source['link'])) {
$links = $source['link'];
if (is_array($links)) {
foreach ($links as $i => $link) {
$sql = $wpdb->prepare("SELECT id from {$wpdb->dln_news_source} WHERE link = %s", esc_sql($link));
$exists = $wpdb->get_row($sql);
if (empty($exists)) {
$result = $wpdb->insert($wpdb->dln_news_source, array('term_id' => esc_sql($term->term_id), 'link' => esc_sql($link), 'source_type' => esc_sql($source['source_type']), 'tags' => esc_sql($source['tags']), 'type' => esc_sql($source['type'])));
}
if (is_wp_error($result)) {
var_dump($result);
}
}
}
}
}
}
exit;
}
示例3: _mla_ajax_add_flat_term
/**
* Add flat taxonomy term from "checklist" meta box on the Media Manager Modal Window
*
* Adapted from the WordPress post_categories_meta_box() in /wp-admin/includes/meta-boxes.php.
*
* @since 2.20
*
* @param string The taxonomy name, from $_POST['action']
*
* @return void Sends JSON response with updated HTML for the checklist
*/
private static function _mla_ajax_add_flat_term($key)
{
$taxonomy = get_taxonomy($key);
check_ajax_referer($_POST['action'], '_ajax_nonce-add-' . $key, true);
if (!current_user_can($taxonomy->cap->edit_terms)) {
wp_die(-1);
}
$new_names = explode(',', $_POST['new' . $key]);
$new_terms_markup = '';
foreach ($new_names as $name) {
if ('' === sanitize_title($name)) {
continue;
}
if (!($id = term_exists($name, $key))) {
$id = wp_insert_term($name, $key);
}
if (is_wp_error($id)) {
continue;
}
if (is_array($id)) {
$id = absint($id['term_id']);
} else {
continue;
}
$term = get_term($id, $key);
$name = $term->name;
$new_terms_markup .= "<li id='{$key}-{$id}'><label class='selectit'><input value='{$name}' type='checkbox' name='tax_input[{$key}][]' id='in-{$key}-{$id}' checked='checked' />{$name}</label></li>\n";
}
// foreach new_name
$input_new_parent_name = "new{$key}_parent";
$supplemental = "<input type='hidden' name='{$input_new_parent_name}' id='{$input_new_parent_name}' value='-1' />";
$add = array('what' => $key, 'id' => $id, 'data' => $new_terms_markup, 'position' => -1, 'supplemental' => array('newcat_parent' => $supplemental));
$x = new WP_Ajax_Response($add);
$x->send();
}
示例4: add_label
public function add_label()
{
$data = stripslashes_deep($_POST);
$post_id = !empty($data['post_id']) ? $data['post_id'] : false;
$post_ids = !empty($data['post_ids']) ? array_map('intval', $data['post_ids']) : array();
if ($post_id) {
$post_ids[] = $post_id;
}
$term = !empty($data['term']) ? $data['term'] : false;
if (!$term) {
$this->_out(new Upfront_JsonResponse_Error("No term"));
}
$res = wp_insert_term($term, 'media_label');
if (is_wp_error($res)) {
$this->_out(new Upfront_JsonResponse_Error("Something went wrong"));
}
if ($post_ids) {
$result = array();
foreach ($post_ids as $post_id) {
$label_objs = wp_get_object_terms($post_id, 'media_label');
$labels = array();
foreach ($label_objs as $label) {
$labels[] = (int) $label->term_id;
}
$labels[] = (int) $res['term_id'];
$result[$post_id] = wp_set_object_terms($post_id, $labels, 'media_label');
}
$this->_out(new Upfront_JsonResponse_Success($result));
} else {
$this->_out(new Upfront_JsonResponse_Success($res));
}
}
示例5: dwqa_posttype_init
function dwqa_posttype_init()
{
global $dwqa_options;
extract(dwqa_get_rewrite_slugs());
/* Question Posttype Registration */
$question_labels = array('name' => __('Question', 'dwqa'), 'singular_name' => __('Question', 'dwqa'), 'add_new' => __('Add New', 'theme'), 'add_new_item' => __('Add New Question', 'dwqa'), 'edit_item' => __('Edit Question'), 'new_item' => __('New Question', 'dwqa'), 'all_items' => __('All Questions', 'dwqa'), 'view_item' => __('View Question', 'dwqa'), 'search_items' => __('Search Question', 'dwqa'), 'not_found' => __('No questions found', 'dwqa'), 'not_found_in_trash' => __('No questions found in Trash', 'dwqa'), 'parent_item_colon' => '', 'menu_name' => __('DW Q&A', 'dwqa'));
$question_args = array('labels' => $question_labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => true, 'rewrite' => array('slug' => $question_rewrite, 'with_front' => false), 'has_archive' => true, 'hierarchical' => true, 'menu_icon' => '', 'supports' => array('title', 'editor', 'comments', 'author', 'page-attributes'));
register_post_type('dwqa-question', $question_args);
/* Question Posttype Registration */
$answer_labels = array('name' => __('Answer', 'dwqa'), 'singular_name' => __('Answer', 'dwqa'), 'add_new' => __('Add New', 'dwqa'), 'add_new_item' => __('Add new answer', 'dwqa'), 'edit_item' => __('Edit answer', 'dwqa'), 'new_item' => __('New Answer', 'dwqa'), 'all_items' => __('All Answers', 'dwqa'), 'view_item' => __('View Answer', 'dwqa'), 'search_items' => __('Search Answer', 'dwqa'), 'not_found' => __('No Answers found', 'dwqa'), 'not_found_in_trash' => __('No Answers found in Trash', 'dwqa'), 'parent_item_colon' => '', 'menu_name' => __('Answer', 'dwqa'));
$answer = array('labels' => $answer_labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => 'edit.php?post_type=dwqa-question', 'query_var' => true, 'rewrite' => true, 'has_archive' => false, 'hierarchical' => true, 'menu_icon' => '', 'supports' => array('title', 'editor', 'comments', 'custom-fields', 'author', 'page-attributes'));
register_post_type('dwqa-answer', $answer);
// Question Taxonomies ( Tag, Category register for Question Posttype)
// Question Categories
$question_category_labels = array('name' => _x('Categories', 'taxonomy general name'), 'singular_name' => _x('Category', 'taxonomy singular name'), 'search_items' => __('Search Categories', 'dwqa'), 'all_items' => __('All Categories', 'dwqa'), 'parent_item' => __('Parent Category', 'dwqa'), 'parent_item_colon' => __('Parent Category:', 'dwqa'), 'edit_item' => __('Edit Category', 'dwqa'), 'update_item' => __('Update Category', 'dwqa'), 'add_new_item' => __('Add New Category', 'dwqa'), 'new_item_name' => __('New Category Name', 'dwqa'), 'menu_name' => __('Question Categories', 'dwqa'));
register_taxonomy('dwqa-question_category', array('dwqa-question'), array('hierarchical' => true, 'labels' => $question_category_labels, 'show_ui' => true, 'query_var' => true, 'rewrite' => array('slug' => $question_category_rewrite, 'with_front' => false)));
// Question Tags
$question_tag_labels = array('name' => _x('Tags', 'taxonomy general name'), 'singular_name' => _x('Tag', 'taxonomy singular name'), 'search_items' => __('Search Tags', 'dwqa'), 'popular_items' => __('Popular Tags', 'dwqa'), 'all_items' => __('All Tags', 'dwqa'), 'parent_item' => null, 'parent_item_colon' => null, 'edit_item' => __('Edit Tag', 'dwqa'), 'update_item' => __('Update Tag', 'dwqa'), 'add_new_item' => __('Add New Tag', 'dwqa'), 'new_item_name' => __('New Tag Name', 'dwqa'), 'separate_items_with_commas' => __('Separate tags with commas', 'dwqa'), 'add_or_remove_items' => __('Add or remove tags', 'dwqa'), 'choose_from_most_used' => __('Choose from the most used tags', 'dwqa'), 'menu_name' => __('Question Tags', 'dwqa'));
register_taxonomy('dwqa-question_tag', array('dwqa-question'), array('hierarchical' => false, 'labels' => $question_tag_labels, 'show_ui' => true, 'update_count_callback' => '_update_post_term_count', 'query_var' => true, 'rewrite' => array('slug' => $question_tag_rewrite, 'with_front' => false)));
// Create default category for dwqa question type when dwqa plugin is actived
$cats = get_categories(array('type' => 'dwqa-question', 'hide_empty' => 0, 'taxonomy' => 'dwqa-question_category'));
if (empty($cats)) {
wp_insert_term('Questions', 'dwqa-question_category');
}
// update term rewrite rule
dwqa_update_term_rewrite_rules();
}
示例6: processTaxonomy
private function processTaxonomy(&$taxonomy)
{
$currentTerms = get_terms($taxonomy->slug, array('hide_empty' => false));
$done = false;
while (!$done) {
$deferred = 0;
foreach ($taxonomy->terms as &$term) {
if (!$term->done) {
$parentId = $this->parentId($term->term->parent, $taxonomy);
if ($parentId || $term->term->parent == 0) {
$existingTermId = $this->findExistingTerm($term, $currentTerms);
$args = array('description' => $term->term->description, 'parent' => $parentId, 'slug' => $term->term->slug, 'term_group' => $term->term->term_group, 'name' => $term->term->name);
if ($existingTermId > 0) {
$ret = wp_update_term($existingTermId, $taxonomy->slug, $args);
$term->id = $existingTermId;
} else {
$id = wp_insert_term($term->term->name, $taxonomy->slug, $args);
$term->id = $id['term_id'];
}
$term->done = true;
} else {
++$deferred;
}
}
if ($deferred == 0) {
$done = true;
}
}
}
}
示例7: woocommerce_osc_run_cats
function woocommerce_osc_run_cats($parent = 0, $parent_term_id = 0)
{
global $wpdb, $oscdb, $import_cat_counter;
$categories = $oscdb->get_results("SELECT c.*, cd.* FROM categories c, categories_description cd WHERE c.categories_id=cd.categories_id AND cd.language_id=1 AND c.parent_id='" . (int) $parent . "'", ARRAY_A);
if (!empty($categories)) {
foreach ($categories as $category) {
if (!is_wp_error($category)) {
$term = term_exists($category['categories_name'], 'product_cat', (int) $parent_term_id);
// array is returned if taxonomy is given
if ((int) $term['term_id'] == 0) {
$term = wp_insert_term($category['categories_name'], 'product_cat', array('parent' => $parent_term_id));
delete_option('product_cat_children');
// clear the cache
$attach_id = 0;
if ($category['categories_image'] != '') {
$url = rtrim($_POST['store_url'], '/') . '/images/' . urlencode($category['categories_image']);
$attach_id = woocommerce_osc_import_image($url);
}
add_woocommerce_term_meta($term['term_id'], 'order', $category['sort_order']);
add_woocommerce_term_meta($term['term_id'], 'display_type', '');
add_woocommerce_term_meta($term['term_id'], 'thumbnail_id', (int) $attach_id);
add_woocommerce_term_meta($term['term_id'], 'osc_id', $category['categories_id']);
woocommerce_osc_run_cats($category['categories_id'], $term['term_id']);
$import_cat_counter++;
} else {
woocommerce_osc_run_cats($category['categories_id'], $term['term_id']);
}
}
}
}
}
示例8: un_do_db_upgrade
function un_do_db_upgrade()
{
global $un_default_options, $wp_roles, $wpdb;
$icons = array('idea' => 'icon-lightbulb', 'question' => 'icon-question-sign', 'problem' => 'icon-exclamation-sign', 'praise' => 'icon-heart');
$plural = array('idea' => __('Ideas', 'usernoise'), 'question' => __('Questions', 'usernoise'), 'problem' => __('Problems', 'usernoise'), 'praise' => __('Praises', 'usernoise'));
$index = 0;
$wpdb->un_termmeta = $wpdb->prefix . "un_termmeta";
if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->un_termmeta}'") != $wpdb->un_termmeta) {
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
$sql = "CREATE TABLE `{$wpdb->un_termmeta}` (\n\t\t\t`meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t`un_term_id` bigint(20) unsigned NOT NULL DEFAULT '0',\n\t\t\t`meta_key` varchar(255) DEFAULT NULL,\n\t\t\t`meta_value` longtext,\n\t\t\tPRIMARY KEY (`meta_id`),\n\t\t\tKEY `un_term_id` (`un_term_id`),\n\t\t\tKEY `meta_key` (`meta_key`)\n\t\t);";
dbDelta($sql);
}
foreach (array('idea' => __('Idea', 'usernoise'), 'question' => __('Question', 'usernoise'), 'problem' => __('Problem', 'usernoise'), 'praise' => __('Praise', 'usernoise')) as $type => $value) {
if (null == ($term = get_term_by('slug', $type, 'feedback_type', ARRAY_A))) {
$term = wp_insert_term($value, FEEDBACK_TYPE, array('slug' => $type));
}
if (null == un_get_term_meta($term['term_id'], 'icon')) {
un_add_term_meta($term['term_id'], 'icon', $icons[$type], true);
un_add_term_meta($term['term_id'], 'plural', $plural[$type], true);
un_add_term_meta($term['term_id'], 'position', $index, true);
}
$index++;
}
if (!isset($wp_roles)) {
$wp_roles = new WP_Roles();
}
foreach (un_get_capable_roles() as $role) {
foreach (un_get_feedback_capabilities() as $cap) {
$wp_roles->add_cap($role, $cap);
}
}
update_option('un_db_revision', '2');
}
示例9: podcasting_install
/**
* Post installation procedures
*/
function podcasting_install()
{
# Setup the default taxonomy
wp_insert_term('Default Format', 'podcast_format');
# Add Podcasting options to the database
add_option('pod_title', get_option('blogname'), "The podcast's title");
add_option('pod_tagline', get_option('blogdescription'), "The podcast's tagline");
add_option('pod_disabled_enclose', false);
add_option('pod_itunes_summary', '', 'iTunes summary');
add_option('pod_itunes_author', '', 'iTunes author');
add_option('pod_itunes_image', '', 'iTunes image');
add_option('pod_itunes_cat1', '', 'iTunes category 1');
add_option('pod_itunes_cat2', '', 'iTunes category 2');
add_option('pod_itunes_cat3', '', 'iTunes category 3');
add_option('pod_itunes_keywords', '', 'iTunes keywords');
add_option('pod_itunes_explicit', '', 'iTunes explicit');
add_option('pod_itunes_new-feed-url', '', 'iTunes new feed url');
add_option('pod_itunes_ownername', '', 'iTunes owner name');
add_option('pod_itunes_owneremail', '', 'iTunes owner email');
add_option('pod_formats', '', 'Explict settings for podcast formats');
add_option('pod_player_flashvars', '', 'Podcasting player flashvars');
add_option('pod_audio_width', '290', 'Podcasting player width');
add_option('pod_player_use_video', 'no');
add_option('pod_player_location', '', '');
add_option('pod_player_text_above', '', '');
add_option('pod_player_text_before', '', '');
add_option('pod_player_text_below', '', '');
add_option('pod_player_text_link', '', '');
add_option('pod_player_width', '400', 'Podcast player width');
add_option('pod_player_height', '300', 'Podcast player height');
add_option('pod_video_flashvars', '', 'Podcasting video flashvars');
add_option('pod_accept_fail', 'no', 'Accept enclosure failure');
}
示例10: dt_geodir_default_taxonomies
function dt_geodir_default_taxonomies($post_type, $categories, $folder_name)
{
global $wpdb, $dummy_image_path;
$cat_count = count($categories);
for ($i = 0; $i < $cat_count; $i++) {
$parent_catid = 0;
if (is_array($categories[$i])) {
$cat_name_arr = $categories[$i];
$count_cat_name_arr = count($cat_name_arr);
for ($j = 0; $j < $count_cat_name_arr; $j++) {
$catname = $cat_name_arr[$j];
if (!term_exists($catname, $post_type . 'category')) {
$last_catid = wp_insert_term($catname, $post_type . 'category', $args = array('parent' => $parent_catid));
if ($j == 0) {
$parent_catid = $last_catid;
}
dt_geodir_insert_taxonomy($post_type, $catname, $folder_name, $last_catid);
}
}
} else {
$catname = $categories[$i];
if (!term_exists($catname, $post_type . 'category')) {
$last_catid = wp_insert_term($catname, $post_type . 'category');
dt_geodir_insert_taxonomy($post_type, $catname, $folder_name, $last_catid);
}
}
}
}
示例11: 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);
}
}
示例12: vtprd_add_dummy_rule_category
public function vtprd_add_dummy_rule_category()
{
$category_list = get_terms('vtprd_rule_category', 'hide_empty=0&parent=0');
if (count($category_list) == 0) {
wp_insert_term(__('Pricing Deals Category', 'vtprd'), 'vtprd_rule_category', "parent=0");
}
}
示例13: vtwpr_add_dummy_rule_category
public function vtwpr_add_dummy_rule_category()
{
$category_list = get_terms('vtwpr_rule_category', 'hide_empty=0&parent=0');
if (count($category_list) == 0) {
wp_insert_term(__('Wholesale Pricing Category', 'vtwpr'), 'vtwpr_rule_category', "parent=0");
}
}
示例14: vtmin_add_dummy_rule_category
public function vtmin_add_dummy_rule_category()
{
$category_list = get_terms('vtmin_rule_category', 'hide_empty=0&parent=0');
if (count($category_list) == 0) {
wp_insert_term(__('Minimum Purchase Category', 'vtmin'), 'vtmin_rule_category', "parent=0");
}
}
示例15: set_up_0_4_0_test_posts
function set_up_0_4_0_test_posts()
{
update_option('wp_gistpen_version', '0.3.1');
register_post_type('gistpens', array());
register_taxonomy('language', array('gistpens'));
foreach (Language::$supported as $lang => $slug) {
$result = wp_insert_term($lang, 'language', array('slug' => $slug));
if (is_wp_error($result)) {
throw new Exception("Failed to insert term.");
}
}
$terms = get_terms('language', 'hide_empty=0');
foreach ($terms as $term) {
$languages[] = $term->slug;
}
$num_posts = count($languages);
$this->gistpens = $this->factory->post->create_many($num_posts, array('post_type' => 'gistpens', 'post_status' => 'publish'), array('post_title' => new WP_UnitTest_Generator_Sequence('Post title %s'), 'post_name' => new WP_UnitTest_Generator_Sequence('Post title %s'), 'post_content' => new WP_UnitTest_Generator_Sequence('Post content %s')));
foreach ($this->gistpens as $gistpen_id) {
// Pick a random language
$num_posts = $num_posts - 1;
$lang_num = rand(0, $num_posts);
// Get the language's id
$lang_slug = $languages[$lang_num];
// Remove the language and reindex the languages array
unset($languages[$lang_num]);
$languages = array_values($languages);
// Give the post a description
update_post_meta($gistpen_id, '_wpgp_gistpen_description', 'This is a description of the Gistpen.');
// Give the post the language
wp_set_object_terms($gistpen_id, $lang_slug, 'language', false);
// Create and set up the user
$user_id = $this->factory->user->create(array('role' => 'administrator'));
wp_set_current_user($user_id);
}
}