| | 4131 | * Updates the post cache for a list of post IDs |
| | 4132 | * |
| | 4133 | * Performs a SQL query to retrieve any uncached posts in the gived post_ids list and cache them. |
| | 4134 | * Therefor, the function, which calls this function, doesn't cause unnecessary SQL queries from get_post(). |
| | 4135 | * |
| | 4136 | * @package WordPress |
| | 4137 | * @subpackage Cache |
| | 4138 | * @since 3.1 |
| | 4139 | * |
| | 4140 | * @param array $post_ids List of post IDs. |
| | 4141 | * @param bool $update_term_cache if the Term Cache should be updated for the given posts |
| | 4142 | * @param bool $update_postmeta_cache if the Post Meta Cache should be updated for the given posts |
| | 4143 | * @return null Doesnt return anything |
| | 4144 | */ |
| | 4145 | function cache_posts($post_ids, $update_term_cache = true, $update_postmeta_cache = true) { |
| | 4146 | // No point in loading posts already in memory |
| | 4147 | foreach ( (array) $post_ids as $key => $id ) |
| | 4148 | if ( wp_cache_get($id, 'posts') ) |
| | 4149 | unset($post_ids[$key]); |
| | 4150 | |
| | 4151 | // No point in doing all this work if all posts are in memory |
| | 4152 | if ( empty($post_ids) ) |
| | 4153 | return; |
| | 4154 | |
| | 4155 | get_posts( array( |
| | 4156 | 'post__in' => $post_ids, |
| | 4157 | 'post_type' => 'any', |
| | 4158 | 'post_status' => 'any', |
| | 4159 | 'update_post_term_cache' => $update_term_cache, |
| | 4160 | 'update_post_meta_cache' => $update_postmeta_cache, |
| | 4161 | 'numberposts' => -1, |
| | 4162 | 'orderby' => 'none', |
| | 4163 | 'suppress_filters' => true |
| | 4164 | )); |
| | 4165 | } |
| | 4166 | |
| | 4167 | /** |