• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP wpcf_get_post_meta函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: wpcf_fields_skype_conditional_filter_post_meta

/**
 * Returns 'skypename' if available.
 *
 * @global type $wpcf
 * @param type $null
 * @param type $object_id
 * @param type $meta_key
 * @param type $single
 * @return type
 */
function wpcf_fields_skype_conditional_filter_post_meta($null, $object_id, $meta_key, $single)
{
    global $wpcf;
    $field = wpcf_admin_fields_get_field($wpcf->field->__get_slug_no_prefix($meta_key));
    if (!empty($field) && $field['type'] == 'skype') {
        $_meta = maybe_unserialize(wpcf_get_post_meta($object_id, $meta_key, $single));
        if (is_array($_meta)) {
            $null = isset($_meta['skypename']) ? $_meta['skypename'] : '';
        }
        /**
         * be sure do not return string if array is expected!
         */
        if (!$single && !is_array($null)) {
            return array($null);
        }
    }
    return $null;
}
开发者ID:SpencerNeitzke,项目名称:types,代码行数:28,代码来源:skype.php


示例2: get_parent

 /**
  * Gets post parent by post type.
  *
  * @param type $post_id
  * @param type $parent_post_type
  * @return type
  */
 public static function get_parent($post_id, $parent_post_type)
 {
     return wpcf_get_post_meta($post_id, '_wpcf_belongs_' . $parent_post_type . '_id', true);
 }
开发者ID:Kilbourne,项目名称:restart,代码行数:11,代码来源:relationship.php


示例3: types_render_field


//.........这里部分代码省略.........
        } else {
            if ($params['post_id'] == '$parent') {
                $current_post = get_post($post_id);
                if (empty($current_post->post_parent)) {
                    return '';
                }
                $post_id = $current_post->post_parent;
                // Types parent
            } else {
                if (strpos($params['post_id'], '$') === 0) {
                    $post_id = intval(WPCF_Relationship::get_parent($post_id, trim($params['post_id'], '$')));
                }
            }
        }
    }
    if (empty($post_id)) {
        return '';
    }
    // Set post
    $post = get_post($post_id);
    if (empty($post)) {
        return '';
    }
    // Get field
    $field = types_get_field($field_id);
    // If field not found return empty string
    if (empty($field)) {
        // Log
        if (!function_exists('wplogger')) {
            require_once WPCF_EMBEDDED_TOOLSET_ABSPATH . '/toolset-common/wplogger.php';
        }
        global $wplogger;
        $wplogger->log('types_render_field call for missing field \'' . $field_id . '\'', WPLOG_DEBUG);
        return '';
    }
    // Set field
    $wpcf->field->set($post, $field);
    // See if repetitive
    if (types_is_repetitive($field)) {
        $wpcf->repeater->set($post_id, $field);
        $_meta = $wpcf->repeater->_get_meta();
        $meta = $_meta['custom_order'];
        // Sometimes if meta is empty - array(0 => '') is returned
        if (count($meta) == 1 && reset($meta) == '') {
            return '';
        }
        if (!empty($meta)) {
            $output = '';
            if (isset($params['index'])) {
                $index = $params['index'];
            } else {
                $index = '';
            }
            // Allow wpv-for-each shortcode to set the index
            $index = apply_filters('wpv-for-each-index', $index);
            if ($index === '') {
                $output = array();
                foreach ($meta as $temp_key => $temp_value) {
                    $params['field_value'] = $temp_value;
                    $temp_output = types_render_field_single($field, $params, $content, $code, $temp_key);
                    if (!empty($temp_output)) {
                        $output[] = $temp_output;
                    }
                }
                if (!empty($output) && isset($params['separator']) && $params['separator'] !== '') {
                    $output = implode(html_entity_decode($params['separator']), $output);
                } else {
                    if (!empty($output)) {
                        $output = implode(' ', $output);
                    } else {
                        return '';
                    }
                }
            } else {
                // Make sure indexed right
                $_index = 0;
                foreach ($meta as $temp_key => $temp_value) {
                    if ($_index == $index) {
                        $params['field_value'] = $temp_value;
                        return types_render_field_single($field, $params, $content, $code, $temp_key);
                    }
                    $_index++;
                }
                // If missed index
                return '';
            }
            $html = $output;
        } else {
            return '';
        }
    } else {
        // Non-repetitive field
        $params['field_value'] = wpcf_get_post_meta($post_id, wpcf_types_get_meta_prefix($field) . $field['slug'], true);
        if ($params['field_value'] == '' && $field['type'] != 'checkbox') {
            return '';
        }
        $html = types_render_field_single($field, $params, $content, $code, $wpcf->field->meta_object->meta_id);
    }
    return $wpcf->field->html($html, $params);
}
开发者ID:axeljohansson1988,项目名称:oddcv,代码行数:101,代码来源:frontend.php


示例4: types_child_posts

/**
 * Gets posts that belongs to current post.
 * 
 * @global type $post
 * @param type $post_type
 * @param type $args
 * @return type 
 */
function types_child_posts($post_type, $args = array())
{
    static $cache = array();
    if (isset($args['post_id'])) {
        $post = $args['post_id'] != '0' ? get_post($args['post_id']) : null;
    } else {
        global $post;
    }
    if (empty($post->ID)) {
        return array();
    }
    $cache_key = md5($post->ID . serialize(func_get_args()));
    if (isset($cache[$cache_key])) {
        return $cache[$cache_key];
    }
    global $wp_post_types;
    // WP allows querying inactive post types
    if (!isset($wp_post_types[$post_type]) || !$wp_post_types[$post_type]->publicly_queryable) {
        return array();
    }
    $defaults = array('post_status' => array('publish'));
    $args = wp_parse_args($args, $defaults);
    WPCF_Loader::loadModel('relationship');
    WPCF_Loader::loadInclude('fields-post');
    $child_posts = WPCF_Relationship_Model::getChildrenByPostType($post, $post_type, array(), array(), $args);
    foreach ($child_posts as $child_post_key => $child_post) {
        $child_posts[$child_post_key]->fields = array();
        $groups = wpcf_admin_post_get_post_groups_fields($child_post);
        foreach ($groups as $group) {
            if (!empty($group['fields'])) {
                // Process fields
                foreach ($group['fields'] as $k => $field) {
                    $data = null;
                    if (types_is_repetitive($field)) {
                        $data = wpcf_get_post_meta($child_post->ID, wpcf_types_get_meta_prefix($field) . $field['slug'], false);
                        // get all field instances
                    } else {
                        $data = wpcf_get_post_meta($child_post->ID, wpcf_types_get_meta_prefix($field) . $field['slug'], true);
                        // get single field instance
                        // handle checkboxes which are one value serialized
                        if ($field['type'] == 'checkboxes' && !empty($data)) {
                            $data = maybe_unserialize($data);
                        }
                    }
                    if (!is_null($data)) {
                        $child_posts[$child_post_key]->fields[$k] = $data;
                    }
                }
            }
        }
    }
    $cache[$cache_key] = $child_posts;
    return $child_posts;
}
开发者ID:lytranuit,项目名称:wordpress,代码行数:62,代码来源:api.php


示例5: __wpcf_fields_date_check_leftover

/**
 * Fix due to a bug saving date as array.
 * 
 * BUGS
 * 'timestamp' is saved without Hour and Minute appended.
 * 
 * @param type $value
 * @param type $field
 */
function __wpcf_fields_date_check_leftover($value, $field, $use_cache = true)
{
    if (empty($value)) {
        return $value;
    }
    if (!is_object($field)) {
        $post_id = wpcf_get_post_id();
        $field_id = isset($field['id']) ? $field['id'] : false;
        $meta_id = isset($field['__meta_id']) ? $field['__meta_id'] : false;
    } else {
        $post_id = isset($field->meta_object->post_id) ? $field->meta_object->post_id : false;
        $field_id = isset($field->cf['id']) ? $field->cf['id'] : false;
        $meta_id = isset($field->meta_object->meta_id) ? $field->meta_object->meta_id : false;
    }
    if (empty($post_id) || empty($meta_id) || empty($field_id)) {
        return $value;
    }
    $field_slug = wpcf_types_get_meta_prefix() . $field_id;
    // Check if cached
    static $cache = array();
    $cache_key = $meta_id;
    if (isset($cache[$cache_key]) && $use_cache) {
        return $cache[$cache_key];
    }
    $_meta = wpcf_get_post_meta($post_id, '_wpcf_' . $field_id . '_hour_and_minute', true);
    /*
     * If meta exists - it's outdated value
     * and Hour and Minute should be appended and removed.
     */
    if (!empty($_meta) && is_array($_meta) && isset($_meta[$meta_id])) {
        $meta = $_meta[$meta_id];
        // Return empty date if can not be calculated
        if (!empty($meta['timestamp']) || !empty($meta['datepicker'])) {
            $meta['timestamp'] = wpcf_fields_date_value_get_filter($meta, $field, 'timestamp', 'check_leftover');
            // Check if calculation needed
            if (isset($meta['hour']) && $meta['hour'] != adodb_date('H', $meta['timestamp']) || isset($meta['minute']) && $meta['minute'] != adodb_date('i', $meta['timestamp'])) {
                $value = wpcf_fields_date_calculate_time($meta);
            }
        }
    }
    // Cache it
    if ($use_cache) {
        $cache[$cache_key] = $value;
    }
    return $value;
}
开发者ID:nhainam,项目名称:wordpress4,代码行数:55,代码来源:functions.php


示例6: getChildrenByPostType

 /**
  * Fetch children by post type.
  *
  * @global object $wpdb
  *
  * @param type $post
  * @param type $post_type
  * @param string $data
  * @param array $params
  * @param array $user_query - Override default query
  * @return type
  */
 public static function getChildrenByPostType($post, $post_type, $data, $params = array(), $user_query = array())
 {
     if (empty($post->ID)) {
         return array();
     }
     global $wpdb;
     $items = array();
     // Merge with user query
     $query = wp_parse_args($user_query, array('post_type' => $post_type, 'numberposts' => -1, 'post_status' => array('publish', 'pending', 'draft', 'future', 'private'), 'meta_key' => '_wpcf_belongs_' . $post->post_type . '_id', 'meta_value' => $post->ID, 'suppress_filters' => 0));
     // Cleanup data
     if (empty($data['fields_setting'])) {
         $data['fields_setting'] = 'all_cf';
     }
     // List items
     if (isset($params['sort']) && isset($params['field'])) {
         // Set sorting
         $query['order'] = esc_attr(strtoupper(strval($params['sort'])));
         if (!preg_match('/^(A|DE)SC$/', $query['order'])) {
             $query['order'] = 'ASC';
         }
         /*
          *
          * Order by title
          */
         if ($params['field'] == '_wp_title') {
             $query['orderby'] = 'title';
             $query = apply_filters('wpcf_relationship_get_children_query', $query, $post, $post_type, $data, esc_attr($params['field']));
             $items = get_posts($query);
             /*
              *
              * Order by parents
              */
         } else {
             if ($params['field'] == '_wpcf_pr_parent') {
                 $query = apply_filters('wpcf_relationship_get_children_query', $query, $post, $post_type, $data, esc_attr($params['field']));
                 $items = get_posts($query);
                 if (!empty($items)) {
                     $include = array();
                     $additional = array();
                     foreach ($items as $item) {
                         $meta = wpcf_get_post_meta($item->ID, '_wpcf_belongs_' . esc_attr($params['post_type_sort_parent']) . '_id', true);
                         if (empty($meta)) {
                             $additional[] = $item;
                             continue;
                         }
                         $include[intval($meta)][] = $item;
                     }
                     if (!empty($include)) {
                         ksort($include, SORT_NUMERIC);
                         if ($query['order'] == 'DESC') {
                             $include = array_reverse($include);
                         }
                         $sorted = array();
                         foreach ($include as $meta_value => $posts) {
                             foreach ($posts as $post) {
                                 $sorted[] = $post;
                             }
                         }
                         $items = array_merge($sorted, $additional);
                     }
                 }
                 /*
                  *
                  * Order by body
                  */
             } else {
                 if ($params['field'] == '_wp_body') {
                     $_query = "\r\r\n                    SELECT p.ID\r\r\n                    FROM {$wpdb->posts} p\r\r\n                    WHERE p.post_type = %s\r\r\n                    AND p.post_status NOT IN ('auto-draft', 'trash', 'inherit')\r\r\n                    ORDER BY p.post_content " . ('ASC' == $query['order'] ? 'ASC' : 'DESC');
                     $sorted = $wpdb->get_results($wpdb->prepare($_query, $post_type));
                     if (!empty($sorted)) {
                         $query['orderby'] = 'post__in';
                         foreach ($sorted as $key => $value) {
                             $query['post__in'][] = $value->ID;
                         }
                     }
                     $query = apply_filters('wpcf_relationship_get_children_query', $query, $post, $post_type, $data, esc_attr($params['field']));
                     $items = get_posts($query);
                     /*
                      *
                      *
                      * Order by custom field
                      */
                 } else {
                     $field = wpcf_admin_fields_get_field(str_replace('wpcf-', '', $params['field']));
                     if (!empty($field)) {
                         $query['orderby'] = isset($field['type']) && in_array($field['type'], array('numeric', 'date')) ? 'meta_value_num' : 'meta_value';
                     }
                     $query = apply_filters('wpcf_relationship_get_children_query', $query, $post, $post_type, $data, esc_attr($params['field']));
//.........这里部分代码省略.........
开发者ID:sonvq,项目名称:passioninvestment,代码行数:101,代码来源:relationship.php


示例7: __wpcf_fields_date_check_leftover

/**
 * Fix due to a bug saving date as array.
 * 
 * BUGS
 * 'timestamp' is saved without Hour and Minute appended.
 * 
 * @param type $value
 * @param type $field
 */
function __wpcf_fields_date_check_leftover($value, $field, $use_cache = true)
{
    if (empty($value)) {
        return $value;
    }
    if (!is_object($field)) {
        $post_id = wpcf_get_post_id();
        $field_id = isset($field['id']) ? $field['id'] : false;
        $meta_id = isset($field['__meta_id']) ? $field['__meta_id'] : false;
    } else {
        $post_id = isset($field->meta_object->post_id) ? $field->meta_object->post_id : false;
        $field_id = isset($field->cf['id']) ? $field->cf['id'] : false;
        $meta_id = isset($field->meta_object->meta_id) ? $field->meta_object->meta_id : false;
    }
    if (empty($post_id) || empty($meta_id) || empty($field_id)) {
        return $value;
    }
    $field_slug = wpcf_types_get_meta_prefix() . $field_id;
    // Check if cached
    static $cache = array();
    $cache_key = $meta_id;
    if (isset($cache[$cache_key]) && $use_cache) {
        return $cache[$cache_key];
    }
    $_meta = wpcf_get_post_meta($post_id, '_wpcf_' . $field_id . '_hour_and_minute', true);
    /*
     * If meta exists - it's outdated value
     * and Hour and Minute should be appended and removed.
     */
    if (!empty($_meta) && is_array($_meta) && isset($_meta[$meta_id])) {
        $meta = $_meta[$meta_id];
        // Return empty date if can not be calculated
        if (!empty($meta['timestamp']) || !empty($meta['datepicker'])) {
            $meta['timestamp'] = wpcf_fields_date_value_get_filter($meta, $field, 'timestamp', 'check_leftover');
            // Check if calculation needed
            if (isset($meta['hour']) && $meta['hour'] != adodb_date('H', $meta['timestamp']) || isset($meta['minute']) && $meta['minute'] != adodb_date('i', $meta['timestamp'])) {
                $value = wpcf_fields_date_calculate_time($meta);
                /*
                 * 
                 * If enabling clearing old values here,
                 * pay attention if field is repetitive.
                 * 
                 * For now - old data is cleared on date save.
                 * wpcf_fields_date_value_save_filter()
                 */
                // Update meta
                //                    $success = update_post_meta( $post_id, $field_slug, $value );
                // Remove additional meta
                //                    if ( $success ) {
                //                        delete_post_meta( $post_id,
                //                                '_wpcf_' . $field_id . '_hour_and_minute' );
                //                    }
            }
        }
    }
    // Cache it
    if ($use_cache) {
        $cache[$cache_key] = $value;
    }
    return $value;
}
开发者ID:CrankMaster336,项目名称:FFW-TR,代码行数:70,代码来源:functions.php



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP wpcf_get_settings函数代码示例发布时间:2022-05-23
下一篇:
PHP wpcf_get_file_url函数代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap