• 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?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter pdg87

    (@pdg87)

    When I call ‘main_atrributes’ as a value, will in get the string from every single custom field with this name, rather than for just the page you are on?

    This could be where I’m going wrong.. if so how do I use the custom field only from current post you are viewing?

    Thread Starter pdg87

    (@pdg87)

    Sorry Im talking to myself ?? But do I need to add this somehow to use the current post custom field value?

    $value = get_field( “main_atrributes” );

    If so how would I work it into the array?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Query using string from custom field as array value’ is closed to new replies.