本文整理汇总了PHP中update_meta_cache函数的典型用法代码示例。如果您正苦于以下问题:PHP update_meta_cache函数的具体用法?PHP update_meta_cache怎么用?PHP update_meta_cache使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了update_meta_cache函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: set_dfi_meta_key
/**
* Mostly the same as `get_metadata()` makes sure any postthumbnail function gets checked at
* the deepest level possible.
*
* @see /wp-includes/meta.php get_metadata()
*
* @param null $null
* @param int $object_id ID of the object metadata is for
* @param string $meta_key Optional. Metadata key. If not specified, retrieve all metadata for
* the specified object.
* @param bool $single Optional, default is false. If true, return only the first value of the
* specified meta_key. This parameter has no effect if meta_key is not specified.
* @return string|array Single metadata value, or array of values
*/
function set_dfi_meta_key($null = null, $object_id, $meta_key, $single)
{
// only affect thumbnails on the frontend, do allow ajax calls
if (is_admin() && (!defined('DOING_AJAX') || !DOING_AJAX) || '_thumbnail_id' != $meta_key) {
return $null;
}
$meta_type = 'post';
$meta_cache = wp_cache_get($object_id, $meta_type . '_meta');
if (!$meta_cache) {
$meta_cache = update_meta_cache($meta_type, array($object_id));
$meta_cache = $meta_cache[$object_id];
}
if (!$meta_key) {
return $meta_cache;
}
if (isset($meta_cache[$meta_key])) {
if ($single) {
return maybe_unserialize($meta_cache[$meta_key][0]);
} else {
return array_map('maybe_unserialize', $meta_cache[$meta_key]);
}
}
if ($single) {
// allow to set an other ID see the readme.txt for details
return apply_filters('dfi_thumbnail_id', get_option('dfi_image_id'), $object_id);
} else {
return array();
}
}
示例2: cache_p2p_meta
/**
* Pre-populates the p2p meta cache to decrease the number of queries.
*/
static function cache_p2p_meta($the_posts, $wp_query)
{
if (isset($wp_query->_p2p_query) && !empty($the_posts)) {
update_meta_cache('p2p', wp_list_pluck($the_posts, 'p2p_id'));
}
return $the_posts;
}
示例3: get_meta_cache
private static function get_meta_cache($object_id, $meta_type)
{
$meta_cache = wp_cache_get($object_id, $meta_type . '_meta');
if (!$meta_cache) {
$meta_cache = update_meta_cache($meta_type, array($object_id));
$meta_cache = $meta_cache[$object_id];
}
return $meta_cache;
}
示例4: register_member_type
/**
* Register all active member types
*
*/
public function register_member_type()
{
//$this->register_post_type();
$is_root_blog = bp_is_root_blog();
//if we are not on the main bp site, switch to it before registering member type
if (!$is_root_blog) {
switch_to_blog(bp_get_root_blog_id());
}
//get all posts in memeber type post type
$post_ids = $this->get_active_member_types();
// get_posts( array( 'post_type'=> bp_member_type_generator()->get_post_type(), 'posts_per_page'=> -1, 'post_status'=> 'publish' ) );
//update meta cache to avoid multiple db calls
update_meta_cache('post', $post_ids);
//build to register the memebr type
$member_types = array();
foreach ($post_ids as $post_id) {
$is_active = get_post_meta($post_id, '_bp_member_type_is_active', true);
$name = get_post_meta($post_id, '_bp_member_type_name', true);
if (!$is_active || !$name) {
continue;
//if not active or no unique key, do not register
}
$enable_directory = get_post_meta($post_id, '_bp_member_type_enable_directory', true);
$directory_slug = get_post_meta($post_id, '_bp_member_type_directory_slug', true);
$has_dir = false;
if ($enable_directory) {
if ($directory_slug) {
$has_dir = $directory_slug;
} else {
$has_dir = true;
}
}
$member_types[$name] = array('labels' => array('name' => get_post_meta($post_id, '_bp_member_type_label_name', true), 'singular_name' => get_post_meta($post_id, '_bp_member_type_label_singular_name', true)), 'has_directory' => $has_dir);
}
foreach ($member_types as $member_type => $args) {
bp_register_member_type($member_type, $args);
}
if (!$is_root_blog) {
restore_current_blog();
}
}
示例5: metadata_exists
function metadata_exists($meta_type, $object_id, $meta_key)
{
if (!$meta_type || !is_numeric($object_id)) {
return false;
}
$object_id = absint($object_id);
if (!$object_id) {
return false;
}
/** This filter is documented in wp-includes/meta.php */
$check = apply_filters("get_{$meta_type}_metadata", null, $object_id, $meta_key, true);
if (null !== $check) {
return (bool) $check;
}
$meta_cache = wp_cache_get($object_id, $meta_type . '_meta');
if (!$meta_cache) {
$meta_cache = update_meta_cache($meta_type, array($object_id));
$meta_cache = $meta_cache[$object_id];
}
if (isset($meta_cache[$meta_key])) {
return true;
}
return false;
}
示例6: get_user_metavalues
/**
* Perform the query to get the $metavalues array(s) needed by _fill_user and _fill_many_users
*
* @since 3.0.0
* @deprecated 3.3.0
*
* @param array $ids User ID numbers list.
* @return array of arrays. The array is indexed by user_id, containing $metavalues object arrays.
*/
function get_user_metavalues($ids)
{
_deprecated_function(__FUNCTION__, '3.3');
$objects = array();
$ids = array_map('intval', $ids);
foreach ($ids as $id) {
$objects[$id] = array();
}
$metas = update_meta_cache('user', $ids);
foreach ($metas as $id => $meta) {
foreach ($meta as $key => $metavalues) {
foreach ($metavalues as $value) {
$objects[$id][] = (object) array('user_id' => $id, 'meta_key' => $key, 'meta_value' => $value);
}
}
}
return $objects;
}
示例7: update_termmeta_cache
/**
* Updates metadata cache for list of term IDs.
*
* Performs SQL query to retrieve all metadata for the terms matching `$term_ids` and stores them in the cache.
* Subsequent calls to `get_term_meta()` will not need to query the database.
*
* @since 4.4.0
*
* @param array $term_ids List of term IDs.
* @return array|false Returns false if there is nothing to update. Returns an array of metadata on success.
*/
function update_termmeta_cache($term_ids)
{
// Bail if term meta table is not installed.
if (get_option('db_version') < 34370) {
return;
}
return update_meta_cache('term', $term_ids);
}
示例8: get_events_between
/**
* get_events_between function
*
* Return all events starting after the given start time and before the
* given end time that the currently logged in user has permission to view.
* If $spanning is true, then also include events that span this
* period. All-day events are returned first.
*
* @param int $start_time limit to events starting after this (local) UNIX time
* @param int $end_time limit to events starting before this (local) UNIX time
* @param array $filter Array of filters for the events returned:
* ['cat_ids'] => non-associatative array of category IDs
* ['tag_ids'] => non-associatative array of tag IDs
* ['post_ids'] => non-associatative array of post IDs
* ['auth_ids'] => non-associatative array of author IDs
* @param bool $spanning also include events that span this period
*
* @return array list of matching event objects
*/
function get_events_between($start_time, $end_time, $filter, $spanning = false)
{
global $wpdb, $ai1ec_events_helper, $ai1ec_localization_helper;
// Convert timestamps to MySQL format in GMT time
$start_time = $ai1ec_events_helper->local_to_gmt($start_time);
$end_time = $ai1ec_events_helper->local_to_gmt($end_time);
// Query arguments
$args = array($start_time, $end_time);
// Get post status Where snippet and associated SQL arguments
$this->_get_post_status_sql($post_status_where, $args);
// Get the Join (filter_join) and Where (filter_where) statements based on
// $filter elements specified
$this->_get_filter_sql($filter);
$wpml_join_particle = $ai1ec_localization_helper->get_wpml_table_join('p.ID');
$wpml_where_particle = $ai1ec_localization_helper->get_wpml_table_where();
$query = $wpdb->prepare("SELECT p.*, e.post_id, i.id AS instance_id, " . "i.start AS start, " . "i.end AS end, " . 'e.allday AS event_allday, ' . "e.recurrence_rules, e.exception_rules, e.recurrence_dates, e.exception_dates, " . "e.venue, e.country, e.address, e.city, e.province, e.postal_code, e.instant_event, " . "e.show_map, e.contact_name, e.contact_phone, e.contact_email, e.cost, e.ticket_url, " . "e.ical_feed_url, e.ical_source_url, e.ical_organizer, e.ical_contact, e.ical_uid " . "FROM {$wpdb->prefix}ai1ec_events e " . "INNER JOIN {$wpdb->posts} p ON p.ID = e.post_id " . $wpml_join_particle . "INNER JOIN {$wpdb->prefix}ai1ec_event_instances i ON e.post_id = i.post_id " . $filter['filter_join'] . "WHERE post_type = '" . AI1EC_POST_TYPE . "' " . $wpml_where_particle . "AND " . ($spanning ? "i.end > %d AND i.start < %d " : "i.start BETWEEN %d AND %d ") . $filter['filter_where'] . $post_status_where . 'GROUP BY i.id ' . 'ORDER BY allday DESC, i.start ASC, post_title ASC', $args);
$events = $wpdb->get_results($query, ARRAY_A);
$id_list = array();
foreach ($events as $event) {
$id_list[] = $event['post_id'];
}
if (!empty($id_list)) {
update_meta_cache('post', $id_list);
}
foreach ($events as &$event) {
$event['start'] = $event['start'];
$event['end'] = $event['end'];
$event['allday'] = $this->_is_all_day($event);
$event = new Ai1ec_Event($event);
}
return $events;
}
示例9: update_termmeta_cache
function update_termmeta_cache($term_ids)
{
return update_meta_cache('term', $term_ids);
}
示例10: wp_make_content_images_responsive
/**
* Filters 'img' elements in post content to add 'srcset' and 'sizes' attributes.
*
* @since 4.4.0
*
* @see wp_image_add_srcset_and_sizes()
*
* @param string $content The raw post content to be filtered.
* @return string Converted content with 'srcset' and 'sizes' attributes added to images.
*/
function wp_make_content_images_responsive($content)
{
if (!preg_match_all('/<img [^>]+>/', $content, $matches)) {
return $content;
}
$selected_images = $attachment_ids = array();
foreach ($matches[0] as $image) {
if (false === strpos($image, ' srcset=') && preg_match('/wp-image-([0-9]+)/i', $image, $class_id) && ($attachment_id = absint($class_id[1]))) {
/*
* If exactly the same image tag is used more than once, overwrite it.
* All identical tags will be replaced later with 'str_replace()'.
*/
$selected_images[$image] = $attachment_id;
// Overwrite the ID when the same image is included more than once.
$attachment_ids[$attachment_id] = true;
}
}
if (count($attachment_ids) > 1) {
/*
* Warm object cache for use with 'get_post_meta()'.
*
* To avoid making a database call for each image, a single query
* warms the object cache with the meta information for all images.
*/
update_meta_cache('post', array_keys($attachment_ids));
}
foreach ($selected_images as $image => $attachment_id) {
$image_meta = get_post_meta($attachment_id, '_wp_attachment_metadata', true);
$content = str_replace($image, wp_image_add_srcset_and_sizes($image, $image_meta, $attachment_id), $content);
}
return $content;
}
示例11: dsq_clear_pending_post_ids
function dsq_clear_pending_post_ids($post_ids)
{
if (count($post_ids) < 1) {
return;
}
global $wpdb;
$posts_query = implode(', ', array_fill(0, count($post_ids), '%s'));
// add as many placeholders as needed
$sql = "\r\n DELETE FROM {$wpdb->postmeta} \r\n WHERE meta_key = 'dsq_needs_sync' AND post_id IN (" . $posts_query . ")\r\n ";
// Call $wpdb->prepare passing the values of the array as separate arguments
$query = call_user_func_array(array($wpdb, 'prepare'), array_merge(array($sql), $post_ids));
$wpdb->query($query);
update_meta_cache('dsq_needs_sync', $post_ids);
}
示例12: get_metadata
/**
* Retrieve metadata for the specified object.
*
* @since 2.9.0
*
* @param string $meta_type Type of object metadata is for (e.g., comment, post, or user)
* @param int $object_id ID of the object metadata is for
* @param string $meta_key Optional. Metadata key. If not specified, retrieve all metadata for
* the specified object.
* @param bool $single Optional, default is false. If true, return only the first value of the
* specified meta_key. This parameter has no effect if meta_key is not specified.
* @return string|array Single metadata value, or array of values
*/
function get_metadata($meta_type, $object_id, $meta_key = '', $single = false)
{
if (!$meta_type) {
return false;
}
if (!($object_id = absint($object_id))) {
return false;
}
$check = apply_filters("get_{$meta_type}_metadata", null, $object_id, $meta_key, $single);
if (null !== $check) {
if ($single && is_array($check)) {
return $check[0];
} else {
return $check;
}
}
$meta_cache = wp_cache_get($object_id, $meta_type . '_meta');
if (!$meta_cache) {
$meta_cache = update_meta_cache($meta_type, array($object_id));
$meta_cache = $meta_cache[$object_id];
}
if (!$meta_key) {
return $meta_cache;
}
if (isset($meta_cache[$meta_key])) {
if ($single) {
return maybe_unserialize($meta_cache[$meta_key][0]);
} else {
return array_map('maybe_unserialize', $meta_cache[$meta_key]);
}
}
if ($single) {
return '';
} else {
return array();
}
}
示例13: get_meta
/**
* @param $object_type
* @param null $_null
* @param int $object_id
* @param string $meta_key
* @param bool $single
*
* @return array|bool|int|mixed|null|string|void
*/
public function get_meta($object_type, $_null = null, $object_id = 0, $meta_key = '', $single = false)
{
$meta_type = $object_type;
if ('post_type' == $meta_type) {
$meta_type = 'post';
}
if (empty($meta_key)) {
$single = false;
}
$object = $this->get_object($object_type, $object_id);
if (empty($object_id) || empty($object)) {
return $_null;
}
$no_conflict = pods_no_conflict_check($meta_type);
if (!$no_conflict) {
pods_no_conflict_on($meta_type);
}
$meta_cache = array();
if (!$single && isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache'])) {
$meta_cache = wp_cache_get($object_id, 'pods_' . $meta_type . '_meta');
if (empty($meta_cache)) {
$meta_cache = wp_cache_get($object_id, $meta_type . '_meta');
if (empty($meta_cache)) {
$meta_cache = update_meta_cache($meta_type, array($object_id));
$meta_cache = $meta_cache[$object_id];
}
}
}
if (empty($meta_cache) || !is_array($meta_cache)) {
$meta_cache = array();
}
$pod = pods($object['name']);
$meta_keys = array($meta_key);
if (empty($meta_key)) {
$meta_keys = array_keys($meta_cache);
}
$key_found = false;
foreach ($meta_keys as $meta_k) {
if (!empty($pod)) {
if (isset($pod->fields[$meta_k])) {
if (empty($pod->id)) {
$pod->fetch($object_id);
$pod->id = $object_id;
}
$key_found = true;
$meta_cache[$meta_k] = $pod->field(array('name' => $meta_k, 'single' => $single, 'get_meta' => true));
if (!is_array($meta_cache[$meta_k]) || !isset($meta_cache[$meta_k][0])) {
if (empty($meta_cache[$meta_k]) && !is_array($meta_cache[$meta_k]) && $single) {
$meta_cache[$meta_k] = array();
} else {
$meta_cache[$meta_k] = array($meta_cache[$meta_k]);
}
}
if (in_array($pod->fields[$meta_k]['type'], PodsForm::tableless_field_types()) && isset($meta_cache['_pods_' . $meta_k])) {
unset($meta_cache['_pods_' . $meta_k]);
}
} elseif (false !== strpos($meta_k, '.')) {
if (empty($pod->id)) {
$pod->fetch($object_id);
$pod->id = $object_id;
}
$key_found = true;
$first = current(explode('.', $meta_k));
if (isset($pod->fields[$first])) {
$meta_cache[$meta_k] = $pod->field(array('name' => $meta_k, 'single' => $single, 'get_meta' => true));
if ((!is_array($meta_cache[$meta_k]) || !isset($meta_cache[$meta_k][0])) && $single) {
if (empty($meta_cache[$meta_k]) && !is_array($meta_cache[$meta_k]) && $single) {
$meta_cache[$meta_k] = array();
} else {
$meta_cache[$meta_k] = array($meta_cache[$meta_k]);
}
}
if (in_array($pod->fields[$first]['type'], PodsForm::tableless_field_types()) && isset($meta_cache['_pods_' . $first])) {
unset($meta_cache['_pods_' . $first]);
}
}
}
}
}
if (!$no_conflict) {
pods_no_conflict_off($meta_type);
}
unset($pod);
// memory clear
if (!$key_found) {
return $_null;
}
if (!$single && isset($GLOBALS['wp_object_cache']) && is_object($GLOBALS['wp_object_cache'])) {
wp_cache_set($object_id, $meta_cache, 'pods_' . $meta_type . '_meta');
}
if (empty($meta_key)) {
//.........这里部分代码省略.........
示例14: convert_datatables_parameter_names_tp15
/**
* Convert old parameter names to new ones in DataTables "Custom Commands".
* DataTables 1.9 used Hungarian notation, while DataTables 1.10+ (used since TablePress 1.5) uses camelCase notation.
*
* @since 1.5.0
*/
public function convert_datatables_parameter_names_tp15()
{
$table_post = $this->tables->get('table_post');
if (empty($table_post)) {
return;
}
// Prime the meta cache with the table options of all tables.
update_meta_cache('post', array_values($table_post));
foreach ($table_post as $table_id => $post_id) {
$table_options = $this->_get_table_options($post_id);
// Nothing to do if there are no "Custom Commands".
if (empty($table_options['datatables_custom_commands'])) {
continue;
}
// Run search/replace.
$old_custom_commands = $table_options['datatables_custom_commands'];
$table_options['datatables_custom_commands'] = strtr($table_options['datatables_custom_commands'], $this->datatables_parameter_mappings);
// No need to save (which runs a DB query) if nothing was replaced in the "Custom Commands".
if ($old_custom_commands === $table_options['datatables_custom_commands']) {
continue;
}
$this->_update_table_options($post_id, $table_options);
}
}
示例15: dsq_clear_pending_post_ids
function dsq_clear_pending_post_ids($post_ids)
{
global $wpdb;
$post_ids_query = "'" . implode("', '", $post_ids) . "'";
$wpdb->query($wpdb->prepare("\r\n DELETE FROM {$wpdb->postmeta} \r\n WHERE meta_key = 'dsq_needs_sync' AND post_id IN (%s)\r\n ", $post_ids_query));
update_meta_cache('dsq_needs_sync', $post_ids);
}