@@ -541,7 +541,7 @@ public function the_posts( array $posts, WP_Query & $wp_query ) {
541
541
$ subs_index = array ();
542
542
foreach ( $ posts as & $ post ) {
543
543
if ( empty ( $ post ->post_title ) || empty ( $ post ->post_excerpt ) || empty ( $ post ->post_content ) ) {
544
- if ( $ default_post = bbl_get_default_lang_post ( $ post ->ID ) )
544
+ if ( $ default_post = $ this -> get_default_lang_post ( $ post ->ID ) )
545
545
$ subs_index [ $ post ->ID ] = $ default_post ->ID ;
546
546
}
547
547
if ( ! $ this ->get_transid ( $ post ) && bbl_get_default_lang_code () == bbl_get_post_lang_code ( $ post ) )
@@ -780,6 +780,7 @@ function clean_post_cache( $post_id ) {
780
780
return ;
781
781
}
782
782
wp_cache_delete ( $ transid , 'bbl_post_translations ' );
783
+ wp_cache_delete ( $ transid , 'bbl_post_translation_ids ' );
783
784
}
784
785
785
786
/**
@@ -1186,7 +1187,7 @@ public function get_new_post_translation_url( $default_post, $lang_code ) {
1186
1187
**/
1187
1188
public function get_default_lang_post ( $ post ) {
1188
1189
$ post = get_post ( $ post );
1189
- $ translations = bbl_get_post_translations ( $ post ->ID );
1190
+ $ translations = $ this -> get_post_translations ( $ post ->ID );
1190
1191
if ( isset ( $ translations [ bbl_get_default_lang_code () ] ) )
1191
1192
return $ translations [ bbl_get_default_lang_code () ];
1192
1193
return false ;
@@ -1205,8 +1206,10 @@ public function get_post_translations( $post ) {
1205
1206
// @FIXME: Is it worth caching here, or can we just rely on the caching in get_objects_in_term and get_posts?
1206
1207
$ transid = $ this ->get_transid ( $ post );
1207
1208
1208
- if ( $ translations = wp_cache_get ( $ transid , 'bbl_post_translations ' ) ) {
1209
- return $ translations ;
1209
+ $ translations = wp_cache_get ( $ transid , 'bbl_post_translation_ids ' );
1210
+
1211
+ if ( false !== $ translations ) {
1212
+ return array_map ( 'get_post ' , $ translations );
1210
1213
}
1211
1214
1212
1215
# @TODO A transid should never be a wp_error. Check and fix.
@@ -1215,28 +1218,14 @@ public function get_post_translations( $post ) {
1215
1218
}
1216
1219
$ post_ids = get_objects_in_term ( $ transid , 'post_translation ' );
1217
1220
1218
- // Work out all the translated equivalent post types
1219
- $ post_types = array ();
1220
- $ langs = bbl_get_active_langs ();
1221
- foreach ( $ langs as $ lang )
1222
- $ post_types [] = bbl_get_post_type_in_lang ( $ post ->post_type , $ lang ->code );
1223
-
1224
- // Get all the translations in one cached DB query
1225
- $ args = array (
1226
- // We want a clean listing, without any particular language
1227
- 'bbl_translate ' => false ,
1228
- 'include ' => $ post_ids ,
1229
- 'post_type ' => $ post_types ,
1230
- 'post_status ' => array ( 'publish ' , 'pending ' , 'draft ' , 'future ' ),
1231
- );
1232
- $ posts = get_posts ( $ args );
1233
1221
$ translations = array ();
1234
- foreach ( $ posts as $ post )
1235
- $ translations [ $ this ->get_post_lang_code ( $ post ) ] = $ post ;
1222
+ $ post_ids = array_filter ( $ post_ids );
1223
+ foreach ( $ post_ids as $ post_id )
1224
+ $ translations [ $ this ->get_post_lang_code ( $ post_id ) ] = $ post_id ;
1236
1225
1237
- wp_cache_set ( $ transid , $ translations , 'bbl_post_translations ' );
1226
+ wp_cache_set ( $ transid , $ translations , 'bbl_post_translation_ids ' );
1238
1227
1239
- return $ translations ;
1228
+ return array_map ( ' get_post ' , $ translations ) ;
1240
1229
}
1241
1230
1242
1231
/**
@@ -1515,6 +1504,7 @@ function set_transid( $post, $transid = false ) {
1515
1504
}
1516
1505
// Delete anything in there currently
1517
1506
wp_cache_delete ( $ transid , 'bbl_post_translations ' );
1507
+ wp_cache_delete ( $ transid , 'bbl_post_translation_ids ' );
1518
1508
}
1519
1509
$ result = wp_set_object_terms ( $ post ->ID , $ transid , 'post_translation ' );
1520
1510
if ( is_wp_error ( $ result ) ) {
0 commit comments