Firstly, what I am trying to do is display posts from Category x on posts from Category y where text from a custom field on post from Cat y matches text from one of 2 custom fields on cat x.
I am using Advanced Custom Fields and have a custom text field on each post from cat x and y to store a list of attributes. e.g. red,car,sports,alloys.
I then want to check to see if they match up between posts and pull in the post where they do.
The trouble I am having is getting the custom field value (text field) and then passing it into the array) The text field contains comma seperated values e.g. "car", "red" if I print the field it shows this. I have tried converting the string to an array using explode, but still it is returning nothig. If I manually add "car", "red" to the array, it works.
I am currently using WP_Query, my latest query is:
<?php
$list = get_field( "main_attributes" );
$arr = array($list);
$array = explode(',', $list);
$args = array(
'meta_query' => array(
'relation' => 'OR',
array(
'key' => 'style_atrributes',
'value' => $array,
'compare' => 'IN'
),
array(
'key' => 'car_atrributes',
'value' => '$array',
'compare' => 'IN'
),
),
);
$custom_query = new WP_Query($args);
while($custom_query->have_posts()) : $custom_query->the_post(); ?>
<div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
<?php the_content(); ?>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); // reset the query ?>