Query using string from custom field as array value
-
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 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.
Firstly, is there a much better way of doing this?
I am currently trying WP_Query. My query is like this:
$args = array( 'meta_query' => array( 'relation' => 'OR', array( 'key' => 'style_atrributes', 'value' => array('main_atrributes'), 'compare' => 'LIKE' ), array( 'key' => 'car_atributes', 'value' => array('main_atrributes'), 'compare' => 'LIKE' ), ), );I have placed this in the post template for category y. As above it just displays all posts from cat x. If I tweak it and change the array to (‘red’, ‘car’) it works and pulls in the correct posts.
Is it possible to use text as part of an array? I have tried storing the text as “red”, “car” and that didnt work either. If I print the field out it displays as above.
Anyone point me in the right direction?
The topic ‘Query using string from custom field as array value’ is closed to new replies.