本文整理汇总了PHP中add_term_meta函数的典型用法代码示例。如果您正苦于以下问题:PHP add_term_meta函数的具体用法?PHP add_term_meta怎么用?PHP add_term_meta使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了add_term_meta函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save_category_meta
/**
* Save Category meta data
*/
function save_category_meta($term_id)
{
if (!get_term_meta($term_id, 'ac_category_featured_image')) {
add_term_meta($term_id, 'ac_category_featured_image', '', true);
}
if (!get_term_meta($term_id, 'ac_category_color')) {
add_term_meta($term_id, 'ac_category_color', '', true);
}
if (!get_term_meta($term_id, 'ac_category_icon')) {
add_term_meta($term_id, 'ac_category_icon', '', true);
}
if (!get_term_meta($term_id, 'ac_category_icon_url')) {
add_term_meta($term_id, 'ac_category_icon_url', '', true);
}
if (isset($_POST['ac_category_featured_image'])) {
$ac_category_featured_image = esc_url($_POST['ac_category_featured_image']);
update_term_meta($term_id, 'ac_category_featured_image', $ac_category_featured_image);
}
if (isset($_POST['ac_category_color'])) {
$ac_category_color = esc_attr($_POST['ac_category_color']);
update_term_meta($term_id, 'ac_category_color', $ac_category_color);
}
if (isset($_POST['ac_category_icon'])) {
$ac_category_icon = $_POST['ac_category_icon'];
update_term_meta($term_id, 'ac_category_icon', $ac_category_icon);
}
if (isset($_POST['ac_category_icon_url'])) {
$ac_category_icon_url = esc_url($_POST['ac_category_icon_url']);
update_term_meta($term_id, 'ac_category_icon_url', $ac_category_icon_url);
}
}
示例2: the_seo_framework_do_upgrade_2701
/**
* Upgrades term metadata for version 2701.
*
* @since 2.7.0
*/
function the_seo_framework_do_upgrade_2701()
{
$term_meta = get_option('autodescription-term-meta');
foreach ((array) $term_meta as $term_id => $meta) {
add_term_meta($term_id, THE_SEO_FRAMEWORK_TERM_OPTIONS, $meta, true);
}
update_option('the_seo_framework_upgraded_db_version', '2701');
}
示例3: save_feature_category_meta
function save_feature_category_meta($term_id, $tt_id)
{
if (isset($_POST['meta-keywords']) && '' !== $_POST['meta-keywords']) {
$group = esc_attr($_POST['meta-keywords']);
add_term_meta($term_id, 'meta-keywords', $group, true);
}
}
示例4: bottom_text_taxonomy_edit_meta_field
function bottom_text_taxonomy_edit_meta_field($term)
{
// put the term ID into a variable
$t_id = $term->term_id;
// retrieve the existing value(s) for this meta field. This returns an array
$term_meta = get_term_meta($t_id, 'cat_meta');
if (!$term_meta) {
$term_meta = add_term_meta($t_id, 'cat_meta', '');
}
?>
<tr class="form-field">
<th scope="row" valign="top"><label for="term_meta[cat_footer]"><?php
_e('Bottom Content', 'flatsome');
?>
</label></th>
<td>
<?php
$content = isset($term_meta[0]['cat_footer']) ? esc_attr($term_meta[0]['cat_footer']) : '';
echo '<textarea id="term_meta[cat_footer]" name="term_meta[cat_footer]">' . $content . '</textarea>';
?>
<p class="description"><?php
_e('Enter a value for this field. Shortcodes are allowed. This will be displayed at bottom of the category.', 'flatsome');
?>
</p>
</td>
</tr>
<?php
}
示例5: hocwp_term_add_meta
function hocwp_term_add_meta($term_id, $meta_key, $meta_value, $unique = false)
{
$version = hocwp_get_wp_version();
if (version_compare($version, '4.4', '>=')) {
return add_term_meta($term_id, $meta_key, $meta_value, $unique);
}
return add_metadata('term', $term_id, $meta_key, $meta_value, $unique);
}
示例6: xmlrpc_add_term_meta
function xmlrpc_add_term_meta($site, $term_id, $metadata)
{
foreach ($metadata as $meta_key => $meta_value) {
if (array_key_exists(0, $meta_value) && count($meta_value) == 1) {
$meta_value = $meta_value[0];
}
add_term_meta($term_id, $meta_key, $meta_value);
}
}
示例7: test_order_by_meta_value_num
/**
* @ticket 37151
*/
public function test_order_by_meta_value_num()
{
register_taxonomy('wptests_tax', 'post');
$terms = self::factory()->term->create_many(3, array('taxonomy' => 'wptests_tax'));
add_term_meta($terms[0], 'foo', 10);
add_term_meta($terms[1], 'foo', 1);
add_term_meta($terms[2], 'foo', 100);
$q = new WP_Term_Query(array('taxonomy' => array('wptests_tax'), 'fields' => 'ids', 'hide_empty' => false, 'meta_key' => 'foo', 'orderby' => 'meta_value_num'));
$found = array_map('intval', $q->terms);
$this->assertSame(array($terms[1], $terms[0], $terms[2]), $found);
}
示例8: create_test_object
/**
* Creates the individual test data object.
*
* Create individual posts for testing with. Gathers basic information such
* as title, content, thumbnail, etc. and inserts them with the post. Also
* adds metaboxes if applicable .
*
* @access private
*
* @see TestContent, wp_insert_post, add_post_meta, update_post_meta, $this->random_metabox_content
*
* @param string $slug a custom post type ID.
*/
private function create_test_object($slug)
{
// Get a random title
$title = apply_filters("tc_{$slug}_term_title", TestContent::title());
$return = wp_insert_term($title, $slug, apply_filters("tc_{$slug}_term_arguments", array('description' => TestContent::title(), 'slug' => sanitize_title($title))));
// Then, set a test content flag on the new post for later deletion
add_term_meta($return['term_id'], 'evans_test_content', '__test__', true);
// Check if we have errors and return them or created message
if (is_wp_error($return)) {
error_log($return->get_error_message());
return $return;
} else {
return array('action' => 'created', 'object' => 'term', 'oid' => $return['term_id'], 'type' => $slug, 'link_edit' => admin_url('/edit-tags.php?action=edit&taxonomy=' . $slug . '&tag_ID=' . $return['term_id']), 'link_view' => get_term_link($return['term_id']));
}
}
示例9: handle
function handle($term_id, $tt_id, $taxonomy)
{
if (!isset($_POST[$this->nonce]) || !wp_verify_nonce($_POST[$this->nonce], $this->nonce_action)) {
return $term_id;
}
$fields = $this->fields();
foreach (dp_field_options($fields) as $name => $field) {
$meta_value = get_term_meta($term_id, $name, true);
$new_meta_value = $_POST[$name];
if (is_array($new_meta_value)) {
$new_meta_value = array_filter($new_meta_value);
} elseif ($field['type'] == 'password') {
$new_meta_value = md5($new_meta_vlue);
}
if ($new_meta_value && empty($meta_value)) {
add_term_meta($term_id, $name, $new_meta_value, true);
} elseif ($new_meta_value && $new_meta_value != $meta_value) {
update_term_meta($term_id, $name, $new_meta_value);
} elseif (empty($new_meta_value) && $meta_value) {
delete_term_meta($term_id, $name, $meta_value);
}
}
}
示例10: save_term_meta
/**
* Save a term's meta
*
* @param int $id Term ID
* @param array $term_meta All meta to be saved (set value to null to delete)
* @param bool $strict Whether to delete previously saved meta not in $term_meta
* @param array $fields (optional) The array of fields and their options, for further processing with
*
* @return int Id of the term with the meta
*
* @since 2.0
*/
public function save_term_meta($id, $term_meta = null, $strict = false, $fields = array())
{
if (!function_exists('get_term_meta')) {
return $id;
}
$simple_tableless_objects = PodsForm::simple_tableless_objects();
$conflicted = pods_no_conflict_check('taxonomy');
if (!$conflicted) {
pods_no_conflict_on('taxonomy');
}
if (!is_array($term_meta)) {
$term_meta = array();
}
$id = (int) $id;
$meta = get_term_meta($id);
foreach ($meta as $k => $value) {
if (is_array($value) && 1 == count($value)) {
$meta[$k] = current($value);
}
}
foreach ($term_meta as $meta_key => $meta_value) {
if (null === $meta_value || $strict && '' === $term_meta[$meta_key]) {
$old_meta_value = '';
if (isset($meta[$meta_key])) {
$old_meta_value = $meta[$meta_key];
}
delete_term_meta($id, $meta_key, $old_meta_value);
} else {
$simple = false;
if (isset($fields[$meta_key])) {
$field_data = $fields[$meta_key];
$simple = 'pick' == $field_data['type'] && in_array(pods_var('pick_object', $field_data), $simple_tableless_objects);
}
if ($simple) {
delete_term_meta($id, $meta_key);
update_term_meta($id, '_pods_' . $meta_key, $meta_value);
if (!is_array($meta_value)) {
$meta_value = array($meta_value);
}
foreach ($meta_value as $value) {
add_term_meta($id, $meta_key, $value);
}
} else {
update_term_meta($id, $meta_key, $meta_value);
}
}
}
if ($strict) {
foreach ($meta as $meta_key => $meta_value) {
if (!isset($term_meta[$meta_key])) {
delete_term_meta($id, $meta_key, $meta_value);
}
}
}
if (!$conflicted) {
pods_no_conflict_off('taxonomy');
}
return $id;
}
示例11: save_category_fields
/**
* save_category_fields function.
*
* @param mixed $term_id Term ID being saved
*/
public function save_category_fields($term_id, $tt_id = '')
{
update_term_meta($term_id, 'order', 0);
if (isset($_POST['display_type']) && '' !== $_POST['display_type']) {
$type = in_array($_POST['display_type'], array('documents', 'subcategory', 'both')) ? $_POST['display_type'] : '';
add_term_meta($term_id, 'display_type', $type);
}
if (isset($_POST['docu_cat_thumbnail_id']) && absint($_POST['docu_cat_thumbnail_id']) > 0) {
add_term_meta($term_id, 'thumbnail_id', absint($_POST['docu_cat_thumbnail_id']));
}
}
示例12: save_neighborhood_meta
function save_neighborhood_meta($term_id)
{
global $neighborhood_terms;
foreach ($neighborhood_terms as $t) {
if (isset($_POST['tag-' . $t]) && '' !== $_POST['tag-' . $t]) {
$group = $t == 'agent-email' ? sanitize_email($_POST['tag-' . $t]) : sanitize_title($_POST['tag-' . $t]);
add_term_meta($term_id, 'neighborhood-' . $t, $group, true);
}
}
}
示例13: save_taxonomy
public function save_taxonomy($term_id)
{
if (wp_verify_nonce(cs_get_var('cs-taxonomy-nonce'), 'cs-taxonomy')) {
$errors = array();
$taxonomy = cs_get_var('taxonomy');
foreach ($this->options as $request_value) {
if ($taxonomy == $request_value['taxonomy']) {
$request_key = $request_value['id'];
$request = cs_get_var($request_key, array());
// ignore _nonce
if (isset($request['_nonce'])) {
unset($request['_nonce']);
}
if (isset($request_value['fields'])) {
foreach ($request_value['fields'] as $field) {
if (isset($field['type']) && isset($field['id'])) {
$field_value = cs_get_vars($request_key, $field['id']);
// sanitize options
if (isset($field['sanitize']) && $field['sanitize'] !== false) {
$sanitize_type = $field['sanitize'];
} else {
if (!isset($field['sanitize'])) {
$sanitize_type = $field['type'];
}
}
if (has_filter('cs_sanitize_' . $sanitize_type)) {
$request[$field['id']] = apply_filters('cs_sanitize_' . $sanitize_type, $field_value, $field, $request_value['fields']);
}
// validate options
if (isset($field['validate']) && has_filter('cs_validate_' . $field['validate'])) {
$validate = apply_filters('cs_validate_' . $field['validate'], $field_value, $field, $request_value['fields']);
if (!empty($validate)) {
$meta_value = get_term_meta($term_id, $request_key, true);
$errors[$field['id']] = array('code' => $field['id'], 'message' => $validate, 'type' => 'error');
$default_value = isset($field['default']) ? $field['default'] : '';
$request[$field['id']] = isset($meta_value[$field['id']]) ? $meta_value[$field['id']] : $default_value;
}
}
}
}
}
$request = apply_filters('cs_save_taxonomy', $request, $request_key, $term_id);
if (empty($request)) {
delete_term_meta($term_id, $request_key);
} else {
if (get_term_meta($term_id, $request_key, true)) {
update_term_meta($term_id, $request_key, $request);
} else {
add_term_meta($term_id, $request_key, $request);
}
}
}
}
set_transient('cs-taxonomy-transient', $errors, 10);
}
}
示例14: test_get_term_by_does_not_prime_term_meta_cache
/**
* @ticket 21760
*/
public function test_get_term_by_does_not_prime_term_meta_cache()
{
global $wpdb;
$term_id = $this->factory->term->create(array('name' => 'Burrito', 'taxonomy' => 'post_tag'));
add_term_meta($term_id, 'foo', 'bar');
clean_term_cache($term_id, 'post_tag');
$num_queries = $wpdb->num_queries;
$term = get_term_by('name', 'Burrito', 'post_tag');
$num_queries++;
$this->assertTrue($term instanceof WP_Term);
$this->assertSame($term_id, $term->term_id);
$this->assertEquals($num_queries, $wpdb->num_queries);
$term_meta = get_term_meta($term_id, 'foo', true);
$num_queries++;
$this->assertSame($term_meta, 'bar');
$this->assertEquals($num_queries, $wpdb->num_queries);
}
示例15: add_woocommerce_term_meta
/**
* WooCommerce Term Meta API
*
* WC tables for storing term meta are @deprecated from WordPress 4.4 since 4.4 has its own table.
* This function serves as a wrapper, using the new table if present, or falling back to the WC table.
*
* @todo These functions should be deprecated with notices in a future WC version, allowing users a chance to upgrade WordPress.
* @param mixed $term_id
* @param mixed $meta_key
* @param mixed $meta_value
* @param bool $unique (default: false)
* @return bool
*/
function add_woocommerce_term_meta($term_id, $meta_key, $meta_value, $unique = false)
{
return function_exists('add_term_meta') ? add_term_meta($term_id, $meta_key, $meta_value, $unique) : add_metadata('woocommerce_term', $term_id, $meta_key, $meta_value, $unique);
}