e_id' ) ->where_in( 'target_indexable_id', $indexable_ids ) ->group_by( 'target_indexable_id' ) ->find_array(); // If the above query fails, do not update anything. if ( ! \is_array( $indexable_counts ) ) { return []; } // Get all ID's returned from the query and set them as keys for easy access. $returned_ids = \array_flip( \array_column( $indexable_counts, 'target_indexable_id' ) ); // Loop over the original ID's and search them in the returned ID's. If they don't exist, add them with an incoming count of 0. foreach ( $indexable_ids as $id ) { // Cast the ID to string, as the arrays only contain stringified versions of the ID. $id = \strval( $id ); if ( isset( $returned_ids[ $id ] ) === false ) { $indexable_counts[] = [ 'incoming' => '0', 'target_indexable_id' => $id, ]; } } return $indexable_counts; } /** * Deletes all seo links for the given ids. * * @param int[] $ids The seo link ids. * * @return bool Whether or not the delete was succesfull. */ public function delete_many_by_id( $ids ) { return $this->query() ->where_in( 'id', $ids ) ->delete_many(); } /** * Insert multiple seo links. * * @param SEO_Links[] $links The seo links to be inserted. * * @return bool Whether or not the insert was succesfull. */ public function insert_many( $links ) { return $this->query() ->insert_many( $links ); } }