Complex MYSQL Query

I’m having trouble with a complex custom MYSQL query (the logic is too complex for a regular wp_query)

One of the primary goals of the query is to select posts where either the post_author = $user_id OR the post meta_key ‘contacts’ contains meta_value $associate_id.

The ‘contacts’ meta key is a relational custom field stored in the database as an array like this: a:1:{i:0;s:2:”44″;}. The custom query I’ve written works in PHPMyAdmin, but for the life of me I can’t get the specific logic I just described to work on the WP frontend.

Here is the full custom query right now:

global $wpdb;
global $post;
$query = "
FROM $wpdb->posts, $wpdb->postmeta
$wpdb->posts.ID = $wpdb->postmeta.post_id
AND $wpdb->posts.post_status = 'publish'
AND $wpdb->posts.post_type = 'home'";
if ( !empty($associate_id) ) {
$query .= " AND (
$wpdb->posts.post_author = '$user_id'
OR (
**** $wpdb->postmeta.meta_key = 'contacts'
**** AND $wpdb->postmeta.meta_value LIKE '%$associate_id%'
$query .= " AND (
$wpdb->postmeta.meta_key = 'status'
AND $wpdb->postmeta.meta_value = '$arg_status'
GROUP BY $wpdb->posts.ID
ORDER BY $wpdb->posts.post_date DESC

Lines 14 and 15 (Quadruple starred above) are causing the trouble – if I remove those lines the rest of the query works perfectly. I believe the main issue is with the meta_value comparison on line 15. I’ve tried using = the full array (copied from the database), using double percentage signs, and all sorts of other syntax combinations without success.

I also tried using a different meta_key and meta_value in place of lines 14 and 15, and that filter did work as intended, which means something is specifically wrong with lines 14 and 15.

Any ideas or feedback? Thanks in advance!