update_object_term_cache [ WordPress Function ]
| Parameters: |
|
| Uses: | |
| Returns: |
|
| Defined at: |
|
Updates the cache for Term ID(s).
Will only update the cache for terms not already cached.
The $object_ids expects that the ids be separated by commas, if it is a string.
It should be noted that update_object_term_cache() is very time extensive. It is advised that the function is not called very often or at least not for a lot of terms that exist in a lot of taxonomies. The amount of time increases for each term and it also increases for each taxonomy the term belongs to.
Source
<?php
function update_object_term_cache($object_ids, $object_type) {
if ( empty($object_ids) )
return;
if ( !is_array($object_ids) )
$object_ids = explode(',', $object_ids);
$object_ids = array_map('intval', $object_ids);
$taxonomies = get_object_taxonomies($object_type);
$ids = array();
foreach ( (array) $object_ids as $id ) {
foreach ( $taxonomies as $taxonomy ) {
if ( false === wp_cache_get($id, "{$taxonomy}_relationships") ) {
$ids[] = $id;
break;
}
}
}
if ( empty( $ids ) )
return false;
$terms = wp_get_object_terms($ids, $taxonomies, array('fields' => 'all_with_object_id'));
$object_terms = array();
foreach ( (array) $terms as $term )
$object_terms[$term->object_id][$term->taxonomy][$term->term_id] = $term;
foreach ( $ids as $id ) {
foreach ( $taxonomies as $taxonomy ) {
if ( ! isset($object_terms[$id][$taxonomy]) ) {
if ( !isset($object_terms[$id]) )
$object_terms[$id] = array();
$object_terms[$id][$taxonomy] = array();
}
}
}
foreach ( $object_terms as $id => $value ) {
foreach ( $value as $taxonomy => $terms ) {
wp_cache_add( $id, $terms, "{$taxonomy}_relationships" );
}
}
}
?>
Examples [ wp-snippets.com ]
Top Google zoekresultaten
- (Add multiple post type support to update_object_term_cache())
update_object_term_cache() only accepts one post_type. If a loop contains more than one post type then the object term cache isn't populated and your queries ...
core.trac.wordpress.org - WordPress › Support » fatal error on wordpress upgrade
Fatal error: Call to undefined function update_object_term_cache() in /home/ realmums/public_html/you/wp-includes/post.php on line 1779. What am I doing ...
wordpress.org - Docs for page functions.wp-taxonomy.php
update_object_term_cache (line 157). void update_object_term_cache ( $ object_ids, $object_type). $object_ids; $object_type. update_term_cache (line 162) ...
phpdoc.ftwr.co.uk - update_object_term_cache (WordPress Function) - WPSeek.com
WordPress lookup for update_object_term_cache, a WordPress Function. wpseek.com is a WordPress-centric search tool for developers and theme authors.
wpseek.com