本文整理汇总了PHP中wp_create_term函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_create_term函数的具体用法?PHP wp_create_term怎么用?PHP wp_create_term使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_create_term函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: _insertTestData
protected function _insertTestData()
{
register_taxonomy('public_taxonomy_a', array('post', 'page'), array('public' => true));
register_taxonomy('private_taxonomy_a', array('post'), array('public' => false));
$post_id_a = wp_insert_post(array('post_status' => 'publish', 'post_type' => 'post', 'post_author' => 1, 'post_parent' => 0, 'menu_order' => 0, 'post_content_filtered' => '', 'post_excerpt' => 'This is the excerpt.', 'post_content' => 'This is the content.', 'post_title' => 'Hello World A!', 'post_date' => '2013-04-30 20:33:36', 'post_date_gmt' => '2013-04-30 20:33:36', 'comment_status' => 'open'));
$post_id_b = wp_insert_post(array('post_status' => 'publish', 'post_type' => 'post', 'post_author' => 1, 'post_parent' => 0, 'menu_order' => 0, 'post_content_filtered' => '', 'post_excerpt' => 'This is the excerpt.', 'post_content' => 'This is the content.', 'post_title' => 'Hello World B!', 'post_date' => '2013-04-30 20:33:36', 'post_date_gmt' => '2013-04-30 20:33:36', 'comment_status' => 'open'));
$term_a = wp_create_term('Term In Both', 'public_taxonomy_a');
$term_b = wp_create_term('Term In A', 'public_taxonomy_a');
$term_c = wp_create_term('Term In B', 'public_taxonomy_a');
$term_d = wp_create_term('Term In None', 'public_taxonomy_a');
$term_e = wp_create_term('Term In Private', 'private_taxonomy_a');
wp_set_object_terms($post_id_a, array(intval($term_a['term_id']), intval($term_b['term_id'])), 'public_taxonomy_a');
wp_set_object_terms($post_id_b, array(intval($term_c['term_id'])), 'public_taxonomy_a');
wp_set_object_terms($post_id_a, array(intval($term_e['term_id'])), 'private_taxonomy_a');
return compact('post_id_a', 'post_id_b', 'term_a', 'term_b', 'term_c', 'term_d', 'term_e');
}
开发者ID:katymdc,项目名称:thermal-api,代码行数:16,代码来源:test-Terms.php
示例2: wp_create_tag
/**
* Add a new tag to the database if it does not already exist.
*
* @since 2.3.0
*
* @param int|string $tag_name
* @return array|WP_Error
*/
function wp_create_tag($tag_name)
{
return wp_create_term($tag_name, 'post_tag');
}
开发者ID:nstungxd,项目名称:F2CA5,代码行数:12,代码来源:taxonomy.php
示例3: wanderlist_save_metabox_data
/**
* Save our data once the user publishes or saves their post.
*/
function wanderlist_save_metabox_data($post_id, $post, $update)
{
// Make sure our nonce has been correctly set.
if (!isset($_POST['meta-box-nonce']) || !wp_verify_nonce($_POST['meta-box-nonce'], basename(__FILE__))) {
return $post_id;
}
// Make sure the user has permissions to edit this post.
if (!current_user_can('edit_post', $post_id)) {
return $post_id;
}
// If we're autosaving, don't worry about it right now.
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
return $post_id;
}
// Check to ensure that our post type is the same as our meta box post type.
if ('wanderlist-location' !== $post->post_type) {
return $post_id;
}
// If we've passed all those checks, we should be good to save! Let's go.
if (isset($_POST['wanderlist-geolocation'])) {
$geolocation_value = sanitize_text_field($_POST['wanderlist-geolocation']);
// Store city name, lat and long as post meta.
$lng_value = sanitize_text_field($_POST['wanderlist-lng']);
$lat_value = sanitize_text_field($_POST['wanderlist-lat']);
$city_value = sanitize_text_field($_POST['wanderlist-city']);
$region_value = sanitize_text_field($_POST['wanderlist-region']);
// Store our country as a term in our custom "country" taxonomy.
$country_value = sanitize_text_field($_POST['wanderlist-country']);
// This creates a term if one doesn't already exist, or selects the existing term.
$country_term = wp_create_term($country_value, 'wanderlist-country');
// Make sure our term id is a string (because nobody wants to go to "148" country).
if (is_string($country_term['term_id'])) {
$country_term['term_id'] = (int) $country_term['term_id'];
}
// Remove all country associations and set our new country.
wp_set_object_terms($post_id, $country_term['term_id'], 'wanderlist-country');
// Update post meta.
update_post_meta($post_id, 'wanderlist-location-string', $geolocation_value);
update_post_meta($post_id, 'wanderlist-city', $city_value);
update_post_meta($post_id, 'wanderlist-region', $region_value);
update_post_meta($post_id, 'wanderlist-lat', $lat_value);
update_post_meta($post_id, 'wanderlist-lng', $lng_value);
} else {
$geolocation_value = '';
$lng_value = '';
$lat_value = '';
$city_value = '';
}
if (isset($_POST['wanderlist-arrival-date'])) {
$arrival_date_value = sanitize_text_field($_POST['wanderlist-arrival-date']);
} else {
$arrival_date_value = '';
}
if (isset($_POST['wanderlist-departure-date'])) {
$departure_date_value = sanitize_text_field($_POST['wanderlist-departure-date']);
} else {
$depature_date_value = '';
}
update_post_meta($post_id, 'wanderlist-arrival-date', $arrival_date_value);
update_post_meta($post_id, 'wanderlist-departure-date', $departure_date_value);
}
开发者ID:sarahmonster,项目名称:wanderlist,代码行数:64,代码来源:wanderlist-admin.php
示例4: ADONewConnection
include "../wp-admin/includes/taxonomy.php";
include "adodb5/adodb.inc.php";
include "adodb5/adodb-exceptions.inc.php";
$DB = ADONewConnection($dbdriver);
# eg 'mysql' or 'postgres'
$DB->debug = false;
$DB->SetCharSet('utf8');
// for mysql
$DB->SetFetchMode(2);
// for mysql
$DB->Connect($server, $user, $password, $database);
$subjects = $DB->GetAll("SELECT * FROM `subject`");
global $wpdb;
foreach ($subjects as $subject) {
$tag_id = $wpdb->get_var("SELECT MAX(`term_id`) FROM `wp_terms`");
$tag = wp_create_term($subject['name']);
echo $tag_id;
// $DB->query("INSERT INTO `subject_to_tag` (`subject_id`, `tag_id`) VALUES (".$subject['id'].", ".$tag_id.")");
}
$count = $DB->GetOne("SELECT COUNT(*) FROM `subject_to_tag`");
?>
<html>
<head>
<meta charset='UTF-8' />
</head>
<body>
<?php
echo $count;
?>
开发者ID:yarylo,项目名称:cerkva.pp.ua,代码行数:31,代码来源:subject-to-tag.php
注:本文中的wp_create_term函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论