本文整理汇总了PHP中add_metadata函数的典型用法代码示例。如果您正苦于以下问题:PHP add_metadata函数的具体用法?PHP add_metadata怎么用?PHP add_metadata使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了add_metadata函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setPostMeta
public function setPostMeta($value, $key = null, $postId = null)
{
if ($key === null) {
$key = $this->dataKey;
}
if ($postId === null) {
$postId = $this->getPost()->ID;
}
/*
* if it's a revision save it also to the revision
*/
if (wp_is_post_revision($postId)) {
add_metadata('post', $postId, $key, $value);
}
return update_post_meta($postId, $key, $value);
}
示例2: add_meta
/**
* Add meta data field to a term.
*
*/
public static function add_meta($term_id, $meta_key, $meta_value, $unique = false)
{
if (current_theme_supports('extended-taxonomies')) {
return add_post_meta(self::get_post_for_extended_term($term_id)->ID, $meta_key, $meta_value, $unique);
}
return add_metadata('taxonomy', $term_id, $meta_key, $meta_value, $unique);
}
示例3: update_metadata
function update_metadata($meta_type, $object_id, $meta_key, $meta_value, $prev_value = '')
{
if (!$meta_type || !$meta_key) {
return false;
}
if (!($table = _get_meta_table($meta_type))) {
return false;
}
global $wpdb;
$column = esc_sql($meta_type . '_id');
$id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id';
// expected_slashed ($meta_key)
$meta_key = stripslashes($meta_key);
if (!($meta_id = $wpdb->get_var($wpdb->prepare("SELECT {$id_column} FROM {$table} WHERE meta_key = %s AND {$column} = %d", $meta_key, $object_id)))) {
return add_metadata($meta_type, $object_id, $meta_key, $meta_value);
}
$meta_value = maybe_serialize(stripslashes_deep($meta_value));
$data = compact('meta_value');
$where = array($column => $object_id, 'meta_key' => $meta_key);
if (!empty($prev_value)) {
$prev_value = maybe_serialize($prev_value);
$where['meta_value'] = $prev_value;
}
do_action("update_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $meta_value);
$wpdb->update($table, $data, $where);
wp_cache_delete($object_id, $meta_type . '_meta');
do_action("updated_{$meta_type}_meta", $meta_id, $object_id, $meta_key, $meta_value);
return true;
}
示例4: 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);
}
示例5: test_slashed_key_for_existing_metadata
/**
* @ticket 35795
*/
public function test_slashed_key_for_existing_metadata()
{
global $wpdb;
add_metadata('post', 123, wp_slash('foo\\foo'), 'bar');
update_metadata('post', 123, wp_slash('foo\\foo'), 'baz');
$found = get_metadata('post', 123, 'foo\\foo', true);
$this->assertSame('baz', $found);
}
示例6: save_post
public static function save_post($post_id, $post)
{
if ($parent_id = wp_is_post_revision($post_id) && !wp_is_post_autosave($post_id)) {
$meta = piklist('post_custom', $parent_id);
foreach ($meta as $key => $value) {
add_metadata('post', $post_id, $key, maybe_serialize($value));
}
}
}
示例7: restoreRevision
/**
* @param $postId
* @param $revisionId
*/
public function restoreRevision($postId, $revisionId)
{
$key = $this->getKey();
$revisionValues = get_post_meta($revisionId, $key, false);
delete_metadata('post', $revisionId, $key);
foreach ($revisionValues as $revisionValue) {
add_metadata('post', $revisionId, $key, $revisionValue);
}
}
示例8: create_post
function create_post()
{
$post_data = array('post_content' => $_POST['content'], 'post_name' => $_POST['slug'], 'post_title' => $_POST['title'], 'post_status' => $_POST['post_status'], 'post_type' => $_POST['post_type']);
if (array_key_exists('category', $_POST)) {
$post_data['post_category'] = $_POST['category'];
}
$new_post_ID = wp_insert_post($post_data);
add_metadata('post', $new_post_ID, 'discourse_order', $_POST['order']);
wp_die();
}
示例9: add
/**
* Add a meta field.
*
* @synopsis <id> <key> <value>
*/
public function add($args, $assoc_args)
{
list($object_id, $meta_key, $meta_value) = $args;
$success = add_metadata($this->meta_type, $object_id, $meta_key, $meta_value);
if ($success) {
WP_CLI::success("Added custom field.");
} else {
WP_CLI::error("Failed to add custom field.");
}
}
示例10: wpsc_meta_migrate
function wpsc_meta_migrate($meta_object_type)
{
global $wpdb;
$legacy_meta_table = $wpdb->prefix . 'wpsc_meta';
$sql = "SELECT meta_id, object_id, meta_key, meta_value FROM `{$legacy_meta_table}` WHERE object_type ='%s'";
$old_meta_rows = $wpdb->get_results($wpdb->prepare($sql, 'wpsc_' . $meta_object_type));
foreach ($old_meta_rows as $old_meta_row) {
$meta_data = maybe_unserialize($old_meta_row->meta_value);
add_metadata('wpsc_' . $meta_object_type, $old_meta_row->object_id, $old_meta_row->meta_key, $meta_data, false);
}
}
示例11: update_data
public function update_data($new_value, $single = true)
{
extract($this->data_args(array('new_value' => $new_value, 'single' => $single)));
if ('options-page' === $type) {
return rrze_Meta_Box::update_option($id, $field_id, $new_value, $single);
}
if (!$single) {
return add_metadata($type, $id, $field_id, $new_value, false);
}
return update_metadata($type, $id, $field_id, $new_value);
}
示例12: easy_ads_update_section_meta
function easy_ads_update_section_meta($post_id, $field_name, $value = '')
{
if (empty($value) or !$value) {
$doo = delete_metadata('easy_ads_taxnomy_sections_', $post_id, $field_name, $value);
} elseif (!get_metadata('easy_ads_taxnomy_sections_', $post_id, $field_name)) {
$doo = add_metadata('easy_ads_taxnomy_sections_', $post_id, $field_name, $value);
} else {
$doo = update_metadata('easy_ads_taxnomy_sections_', $post_id, $field_name, $value);
}
return $doo;
}
示例13: pootlepb_revisions_save_post
/**
* Store the Page Builder meta in the revision.
* @param $post_id
* @since 0.1.0
*/
function pootlepb_revisions_save_post($post_id)
{
$parent_id = wp_is_post_revision($post_id);
if ($parent_id) {
// If the panels data meta exists, copy it into the revision.
$panels_data = get_post_meta($parent_id, 'panels_data', true);
if (!empty($panels_data)) {
add_metadata('post', $post_id, 'panels_data', $panels_data);
}
}
}
示例14: add
/**
* Add a meta field.
*
* ## OPTIONS
*
* <id>
* : The ID of the object.
*
* <key>
* : The name of the meta field to create.
*
* [<value>]
* : The value of the meta field. If ommited, the value is read from STDIN.
*
* [--format=<format>]
* : The serialization format for the value. Default is plaintext.
*/
public function add($args, $assoc_args)
{
list($object_id, $meta_key) = $args;
$meta_value = \Terminus::get_value_from_arg_or_stdin($args, 2);
$meta_value = \Terminus::read_value($meta_value, $assoc_args);
$success = \add_metadata($this->meta_type, $object_id, $meta_key, $meta_value);
if ($success) {
\Terminus::success("Added custom field.");
} else {
\Terminus::error("Failed to add custom field.");
}
}
示例15: add
/**
* Update meta field for a user
*
* @param array $args
* @param array $assoc_args
**/
public function add($args, $assoc_args)
{
$object_id = WP_CLI::get_numeric_arg($args, 0, "{$this->meta_type} ID");
$meta_key = self::get_arg_or_error($args, 1, "meta_key");
$meta_value = self::get_arg_or_error($args, 2, "meta_value");
$success = add_metadata($this->meta_type, $object_id, $meta_key, $meta_value);
if ($success) {
WP_CLI::success("Added custom field.");
} else {
WP_CLI::error("Failed to add custom field.");
}
}