Skip to content

Commit e8a392e

Browse files
author
Marco Pereirinha
committed
Fix preload the cache
1 parent e4915d2 commit e8a392e

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

php/relate/class-relationship.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,17 @@ public function flush_cache() {
160160
* @param array $post_ids The post ids.
161161
*/
162162
public static function preload( $post_ids ) {
163+
// Check if the post_ids are objects.
164+
$maybe_ids = array_column( $post_ids, 'ID' );
165+
if ( ! empty( $maybe_ids ) ) {
166+
// If so, make sure to just use the IDs.
167+
$post_ids = $maybe_ids;
168+
}
163169
global $wpdb;
164170
$table_name = Utils::get_relationship_table();
165171
// Do the public_ids.
166172
$list = implode( ', ', array_fill( 0, count( $post_ids ), '%d' ) );
167-
$where = "post_id IN( {$list} )";
173+
$where = "post_id IN ( {$list} )";
168174

169175
$sql = $wpdb->prepare( "SELECT * FROM {$table_name} WHERE {$where}", $post_ids ); // phpcs:ignore WordPress.DB
170176
$posts = $wpdb->get_results( $sql, ARRAY_A ); // phpcs:ignore WordPress.DB

0 commit comments

Comments
 (0)