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


PHP add_post_meta函数代码示例

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


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

示例1: pvbu_setPostViews

function pvbu_setPostViews($postID)
{
    $count_key = 'post_views_by_user';
    $count = get_post_meta($postID, $count_key, true);
    //echo '<script type="text/javascript">console.log('.$count.')</script>';
    $user_array = array();
    if ($count == '') {
        if (is_user_logged_in()) {
            $user_ID = get_current_user_id();
            $user_array[$user_ID] = date("Y-m-d H:i:s");
            add_post_meta($postID, 'post_views_by_user', $user_array);
        }
    } else {
        if (is_user_logged_in()) {
            $user_ID = get_current_user_id();
            var_dump($count[$user_ID]);
            if ($count[$user_ID] == null) {
                $count[$user_ID] = date("Y-m-d H:i:s");
                delete_post_meta($postID, $count_key);
                add_post_meta($postID, 'post_views_by_user', $count);
            } else {
                return;
            }
        }
    }
}
开发者ID:sshuvro58,项目名称:WP_Post_View_by_User,代码行数:26,代码来源:post-view-by-user.php

示例2: like_post

 function like_post($post_id, $action = 'get')
 {
     if (!is_numeric($post_id)) {
         return;
     }
     switch ($action) {
         case 'get':
             $like_count = get_post_meta($post_id, '_qode-like', true);
             if (!$like_count) {
                 $like_count = 0;
                 add_post_meta($post_id, '_qode-like', $like_count, true);
             }
             return '<span class="qode-like-count">' . $like_count . '</span>';
             break;
         case 'update':
             $like_count = get_post_meta($post_id, '_qode-like', true);
             if (isset($_COOKIE['qode-like_' . $post_id])) {
                 return $like_count;
             }
             $like_count++;
             update_post_meta($post_id, '_qode-like', $like_count);
             setcookie('qode-like_' . $post_id, $post_id, time() * 20, '/');
             return '<span class="qode-like-count">' . $like_count . '</span>';
             break;
     }
 }
开发者ID:sdxlgc,项目名称:net-wp_sdgcxl-htdocs,代码行数:26,代码来源:qode-like.php

示例3: comcon_meta_save

function comcon_meta_save()
{
    global $post;
    $post_id = $post->ID;
    if (!isset($_POST['comcon-form-nonce']) || !wp_verify_nonce($_POST['comcon-form-nonce'], basename(__FILE__))) {
        return $post->ID;
    }
    $post_type = get_post_type_object($post->post_type);
    if (!current_user_can($post_type->cap->edit_post, $post_id)) {
        return $post->ID;
    }
    $input = array();
    $input['position'] = isset($_POST['comcon-form-position']) ? $_POST['comcon-form-position'] : '';
    $input['major'] = isset($_POST['comcon-form-major']) ? $_POST['comcon-form-major'] : '';
    $input['order'] = str_pad($input['order'], 3, "0", STR_PAD_LEFT);
    foreach ($input as $field => $value) {
        $old = get_post_meta($post_id, 'comcon-form-' . $field, true);
        if ($value && '' == $old) {
            add_post_meta($post_id, 'comcon-form-' . $field, $value, true);
        } else {
            if ($value && $value != $old) {
                update_post_meta($post_id, 'comcon-form-' . $field, $value);
            } else {
                if ('' == $value && $old) {
                    delete_post_meta($post_id, 'comcon-form-' . $field, $old);
                }
            }
        }
    }
}
开发者ID:ucf-design-group,项目名称:vucf,代码行数:30,代码来源:functions-comcon.php

示例4: handle_upload

 /**
  * Upload
  * Ajax callback function
  *
  * @return string Error or (XML-)response
  */
 static function handle_upload()
 {
     global $wpdb;
     $post_id = isset($_REQUEST['post_id']) ? intval($_REQUEST['post_id']) : 0;
     $field_id = isset($_REQUEST['field_id']) ? $_REQUEST['field_id'] : '';
     check_ajax_referer("rwmb-upload-images_{$field_id}");
     // You can use WP's wp_handle_upload() function:
     $file = $_FILES['async-upload'];
     $file_attr = wp_handle_upload($file, array('test_form' => false));
     //Get next menu_order
     $meta = get_post_meta($post_id, $field_id, false);
     if (empty($meta)) {
         $next = 0;
     } else {
         $meta = implode(',', (array) $meta);
         $max = $wpdb->get_var("\n\t\t\t\t\tSELECT MAX(menu_order) FROM {$wpdb->posts}\n\t\t\t\t\tWHERE post_type = 'attachment'\n\t\t\t\t\tAND ID in ({$meta})\n\t\t\t\t");
         $next = is_numeric($max) ? (int) $max + 1 : 0;
     }
     $attachment = array('guid' => $file_attr['url'], 'post_mime_type' => $file_attr['type'], 'post_title' => preg_replace('/\\.[^.]+$/', '', basename($file['name'])), 'post_content' => '', 'post_status' => 'inherit', 'menu_order' => $next);
     // Adds file as attachment to WordPress
     $id = wp_insert_attachment($attachment, $file_attr['file'], $post_id);
     if (!is_wp_error($id)) {
         wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $file_attr['file']));
         // Save file ID in meta field
         add_post_meta($post_id, $field_id, $id, false);
         wp_send_json_success(self::img_html($id));
     }
     exit;
 }
开发者ID:thonysmith,项目名称:LearnPress,代码行数:35,代码来源:plupload-image.php

示例5: save_postdata

 function save_postdata($post_id)
 {
     // verify if this is an auto save routine.
     // If it is our form has not been submitted, so we dont want to do anything
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return;
     }
     // verify this came from the our screen and with proper authorization,
     // because save_post can be triggered at other times
     if (!wp_verify_nonce($_POST['aceelpress_noncename'], plugin_basename(__FILE__))) {
         return;
     }
     // Check permissions
     if ('page' == $_POST['post_type']) {
         if (!current_user_can('edit_page', $post_id)) {
             return;
         }
     } else {
         if (!current_user_can('edit_post', $post_id)) {
             return;
         }
     }
     // OK, we're authenticated: we need to find and save the data
     $l = new Language();
     if (!($languageIDs = $_POST[$l->getFormName()])) {
         return;
     }
     foreach ($languageIDs as $lid => $val) {
         add_post_meta($post_id, 'accelpress_language_' . $lid, $val, true) or update_post_meta($post_id, 'accelpress_language_' . $lid, $val);
     }
 }
开发者ID:netacceleration,项目名称:accelpress,代码行数:31,代码来源:Language.php

示例6: set_author_on_post

/**
 * Sets an author on a post, with a specified role.
 *
 * This can be used to edit an existing coauthor - for example, changing the role
 * of an author already attached to a post - but it is not guaranteed to
 * preserve order. If the sorted order of authors needs to be preserved, call
 * `update_coauthors_on_post()` and pass the full list of coauthors to update,
 * sorted.
 *
 * @param int|object $post_id Post to set author as "coauthor" on
 * @param object|string $author user_nicename of Author to add on post (or WP_User object)
 * @param object|string $author_role Term or slug of contributor role to set. Defaults to "byline" if empty
 * @return bool True on success, false on failure (if any of the inputs are not acceptable).
 */
function set_author_on_post($post_id, $author, $author_role = false)
{
    global $coauthors_plus;
    if (is_object($post_id) && isset($post_id->ID)) {
        $post_id = $post_id->ID;
    }
    $post_id = intval($post_id);
    if (is_string($author)) {
        $author = $coauthors_plus->get_coauthor_by('user_nicename', $author);
    }
    if (!isset($author->user_nicename)) {
        return false;
    }
    // Only create the byline term if the contributor role is:
    //  - one of the byline roles, as set in register_author_role(), or
    //  - unset, meaning they should default to primary author role.
    if (!$author_role || in_array($author_role, byline_roles())) {
        $coauthors_plus->add_coauthors($post_id, array($author->user_nicename), true);
    }
    if (!$post_id || !$author) {
        return false;
    }
    foreach (get_post_meta($post_id) as $key => $values) {
        if (strpos($key, 'cap-') === 0 && in_array($author->user_nicename, $values)) {
            delete_post_meta($post_id, $key, $author->user_nicename);
        }
    }
    if (!is_object($author_role)) {
        $author_role = get_author_role($author_role);
    }
    if (!$author_role) {
        return false;
    }
    add_post_meta($post_id, 'cap-' . $author_role->slug, $author->user_nicename);
}
开发者ID:serhi,项目名称:Co-Authors-Plus-Roles,代码行数:49,代码来源:author-roles-posts-relationships.php

示例7: save_downloads_meta

function save_downloads_meta($post_id)
{
    global $post, $downloads_meta;
    foreach ($downloads_meta as $meta_box) {
        // Verifica
        /*if ( !wp_verify_nonce( $_POST[$meta_box['name'].'_noncename'], plugin_basename(__FILE__) )) {
        			return $post_id;
        		}*/
        if ('page' == $_POST['post_type']) {
            if (!current_user_can('edit_page', $post_id)) {
                return $post_id;
            }
        } else {
            if (!current_user_can('edit_post', $post_id)) {
                return $post_id;
            }
        }
        $data = $_POST[$meta_box['name'] . '_value'];
        if (get_post_meta($post_id, $meta_box['name'] . '_value') == "") {
            add_post_meta($post_id, $meta_box['name'] . '_value', $data, true);
        } elseif ($data != get_post_meta($post_id, $meta_box['name'] . '_value', true)) {
            update_post_meta($post_id, $meta_box['name'] . '_value', $data);
        } elseif ($data == "") {
            delete_post_meta($post_id, $meta_box['name'] . '_value', get_post_meta($post_id, $meta_box['name'] . '_value', true));
        }
    }
}
开发者ID:Gestiopolis,项目名称:GestiopolisExp1,代码行数:27,代码来源:meta_downloads.php

示例8: create_media_translation

 public function create_media_translation($post_id, $lang)
 {
     $post = get_post($post_id);
     $lang = $this->model->get_language($lang);
     // make sure we get a valid language slug
     // create a new attachment ( translate attachment parent if exists )
     $post->ID = null;
     // will force the creation
     $post->post_parent = $post->post_parent && ($tr_parent = $this->model->post->get_translation($post->post_parent, $lang->slug)) ? $tr_parent : 0;
     $post->tax_input = array('language' => array($lang->slug));
     // assigns the language
     $tr_id = wp_insert_attachment($post);
     // copy metadata, attached file and alternative text
     foreach (array('_wp_attachment_metadata', '_wp_attached_file', '_wp_attachment_image_alt') as $key) {
         if ($meta = get_post_meta($post_id, $key, true)) {
             add_post_meta($tr_id, $key, $meta);
         }
     }
     $this->model->post->set_language($tr_id, $lang);
     $translations = $this->model->post->get_translations($post_id);
     if (!$translations && ($src_lang = $this->model->post->get_language($post_id))) {
         $translations[$src_lang->slug] = $post_id;
     }
     $translations[$lang->slug] = $tr_id;
     $this->model->post->save_translations($tr_id, $translations);
     do_action('pll_translate_media', $post_id, $tr_id, $lang->slug);
     return $tr_id;
 }
开发者ID:phongvan212,项目名称:kinhte,代码行数:28,代码来源:admin-filters-media.php

示例9: two_thousand_twenty_post_like

function two_thousand_twenty_post_like()
{
    $post_like_vars = two_thousand_twenty_post_like_variables();
    if (isset($_POST['post_like'])) {
        // Check for nonce security
        if (!wp_verify_nonce($post_like_vars['nonce'], 'ajax-nonce')) {
            die('Busted!');
        }
        // Check if current user has already liked this post.
        if (!in_array($post_like_vars['user_email'], $post_like_vars['post_like_user'])) {
            // If not add him as metadata with his cookie-user-email as ID.
            add_post_meta($post_like_vars['post_id'], 'post_like_user', $post_like_vars['user_email']);
            // On the other hand we must increase the post like count.
            if (empty($post_like_vars['post_like_count'])) {
                update_post_meta($post_like_vars['post_id'], 'post_like_count', 1);
            } else {
                update_post_meta($post_like_vars['post_id'], 'post_like_count', ++$post_like_vars['post_like_count'][0]);
            }
            // Message to be retrieve by the ajax success event.
            echo get_post_meta($post_like_vars['post_id'], 'post_like_count', true);
        } else {
            // If use has already liked the message is 'already'.
            echo 'already';
        }
    }
    exit;
}
开发者ID:kaplan81,项目名称:my-code-samples,代码行数:27,代码来源:functions.php

示例10: mybox_save_postdata

function mybox_save_postdata($post_id)
{
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
    }
    if (!wp_verify_nonce($_POST['noncename'], plugin_basename(__FILE__))) {
        return;
    }
    if ('page' == $_POST['post_type']) {
        if (!current_user_can('edit_page', $post_id)) {
            return;
        }
    } else {
        if (!current_user_can('edit_post', $post_id)) {
            return;
        }
    }
    // OK, we're authenticated: we need to find and save the data
    //if saving in a custom table, get post_ID
    $post_ID = $_POST['post_ID'];
    //sanitize user input
    $mydata['date'] = strtotime(sanitize_text_field($_POST['boxoption']['date']));
    $mydata['time'] = sanitize_text_field($_POST['boxoption']['time']);
    $mydata['location'] = sanitize_text_field($_POST['boxoption']['location']);
    $save = json_encode($mydata);
    add_post_meta($post_ID, 'boxoption', $save, true) or update_post_meta($post_ID, 'boxoption', $save);
}
开发者ID:nightcrawlerq,项目名称:neurofit,代码行数:27,代码来源:post-options.php

示例11: savemeta

 public static function savemeta($post_id, $post)
 {
     /* Get the post type object. */
     $post_type = get_post_type_object($post->post_type);
     /* Check if the current user has permission to edit the post. */
     if (!current_user_can($post_type->cap->edit_post, $post_id)) {
         return $post_id;
     }
     /* Get the meta key. */
     $meta_key = self::$prefix . $post_id;
     /* Get the posted data and sanitize it for use as an HTML class. */
     $new_meta_value = isset($_POST[self::$prefix]) ? $_POST[self::$prefix] : '';
     /* Get the meta value of the custom field key. */
     $meta_value = get_post_meta($post_id, $meta_key, true);
     /* If a new meta value was added and there was no previous value, add it. */
     if ($new_meta_value && '' == $meta_value) {
         add_post_meta($post_id, $meta_key, $new_meta_value, true);
     } elseif ($new_meta_value && $new_meta_value != $meta_value) {
         update_post_meta($post_id, $meta_key, $new_meta_value);
     } elseif ('' == $new_meta_value && $meta_value) {
         delete_post_meta($post_id, $meta_key, $meta_value);
         if (($ptemplate = self::getPathTheme($post_id)) && file_exists($ptemplate)) {
             unlink($ptemplate);
         }
     }
 }
开发者ID:taeche,项目名称:SoDoEx,代码行数:26,代码来源:jv_header.php

示例12: themeist_plugins_save_plugin_info_meta_box

/**
 * Saves the plugin info meta box.
 *
 * @since 0.1.0
 */
function themeist_plugins_save_plugin_info_meta_box($post_id, $post)
{
    if (!isset($_POST['themeist-plugin-info-meta-box']) || !wp_verify_nonce($_POST['themeist-plugin-info-meta-box'], basename(__FILE__))) {
        return $post_id;
    }
    $post_type = get_post_type_object($post->post_type);
    if (!current_user_can($post_type->cap->edit_post, $post_id)) {
        return $post_id;
    }
    $meta = array('plugin_download_url' => esc_attr(strip_tags($_POST['plugin-download-link'])), 'plugin_repo_url' => esc_url(strip_tags($_POST['plugin-repo-link'])), 'plugin_version_number' => strip_tags($_POST['plugin-version']));
    foreach ($meta as $meta_key => $new_meta_value) {
        /* Get the meta value of the custom field key. */
        $meta_value = get_post_meta($post_id, $meta_key, true);
        /* If a new meta value was added and there was no previous value, add it. */
        if (!empty($new_meta_value) && empty($meta_value)) {
            add_post_meta($post_id, $meta_key, $new_meta_value, true);
        } elseif ($new_meta_value !== $meta_value) {
            update_post_meta($post_id, $meta_key, $new_meta_value);
        } elseif ('' === $new_meta_value && !empty($meta_value)) {
            delete_post_meta($post_id, $meta_key, $meta_value);
        }
    }
    /* We need this b/c draft post's post_name don't get set. */
    $post_name = !empty($post->post_name) ? $post->post_name : sanitize_title($post->post_title);
    if (!term_exists("relationship-{$post_name}", 'doc_relationship')) {
        $args = array('slug' => "relationship-{$post_name}");
        $parent_term = get_term_by('slug', 'relationship-plugins', 'doc_relationship');
        if (!empty($parent_term)) {
            $args['parent'] = $parent_term->term_id;
        }
        wp_insert_term($post->post_title, 'doc_relationship', $args);
    }
}
开发者ID:hchouhan,项目名称:glossary-by-themeist,代码行数:38,代码来源:meta-boxes.php

示例13: copy

 /**
  * Create a Duplicate post
  */
 static function copy($post, $post_title = '', $post_name = '', $post_type = 'sp_report')
 {
     // We don't want to clone revisions
     if ($post->post_type == 'revision') {
         return;
     }
     if ($post->post_type != 'attachment') {
         $status = 'draft';
     }
     $new_post_author = wp_get_current_user();
     $new_post = array('menu_order' => $post->menu_order, 'comment_status' => $post->comment_status, 'ping_status' => $post->ping_status, 'post_author' => $new_post_author->ID, 'post_content' => $post->post_content, 'post_excerpt' => $post->post_excerpt, 'post_mime_type' => $post->post_mime_type, 'post_password' => $post->post_password, 'post_status' => $post->post_status, 'post_title' => empty($post_title) ? $post->post_title : $post_title, 'post_type' => empty($post_type) ? $post->post_type : $post_type);
     if ($post_name != '') {
         $new_post['post_name'] = $post_name;
     }
     /*
     $new_post['post_date'] = $new_post_date =  $post->post_date ;
     $new_post['post_date_gmt'] = get_gmt_from_date($new_post_date);
     */
     $new_post_id = wp_insert_post($new_post);
     // If you have written a plugin which uses non-WP database tables to save
     // information about a post you can hook this action to dupe that data.
     if ($post->post_type == 'page' || function_exists('is_post_type_hierarchical') && is_post_type_hierarchical($post->post_type)) {
         do_action('sp_duplicate_page', $new_post_id, $post);
     } else {
         do_action('sp_duplicate_post', $new_post_id, $post);
     }
     delete_post_meta($new_post_id, '_sp_original');
     add_post_meta($new_post_id, '_sp_original', $post->ID);
     add_post_meta($new_post_id, '_open_count', 0);
     return $new_post_id;
 }
开发者ID:radscheit,项目名称:unicorn,代码行数:34,代码来源:class-sendpress-posts.php

示例14: setAllFields

 public function setAllFields($values)
 {
     if (!update_post_meta($this->_pid, self::META_KEY, $values)) {
         return add_post_meta($this->_pid, self::META_KEY, $values);
     }
     return true;
 }
开发者ID:voxpelli,项目名称:wp-newspapermeta,代码行数:7,代码来源:newspapermeta.php

示例15: save

 function save($post_id)
 {
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return $post_id;
     }
     // Check permissions
     if ('page' == $_POST['post_type']) {
         if (!current_user_can('edit_page', $post_id)) {
             return $post_id;
         }
     } else {
         if (!current_user_can('edit_post', $post_id)) {
             return $post_id;
         }
     }
     // Verify nonce
     if (!wp_verify_nonce($_POST[$this->conf['id'] . '_noncename'], plugin_basename(__FILE__))) {
         return $post_id;
     }
     foreach ($this->options as $v) {
         if (isset($v['id']) && !empty($v['id'])) {
             $value = $_POST[$v['id']];
             if (get_post_meta($post_id, $v['id']) == "") {
                 add_post_meta($post_id, $v['id'], $value, true);
             } elseif ($value != get_post_meta($post_id, $v['id'], true)) {
                 update_post_meta($post_id, $v['id'], $value);
             } elseif ($value == "") {
                 delete_post_meta($post_id, $v['id'], get_post_meta($post_id, $v['id'], true));
             }
         }
     }
 }
开发者ID:johnulist,项目名称:WPHP-Framework,代码行数:32,代码来源:metas.php


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