Forums

[resolved] WP_Query by Meta Key & Value (2 posts)

  1. AngelEyes
    Member
    Posted 3 months ago #

    I have a meta key called Affiliate and a value that is the same over several posts. I can't get the query to return anything as expected. the loop needs to be dynamic for each page so I'm getting the value of that meta key (custom field) and saving it as $affiliate. I'm then plugging it into my query but i can't get it to work. Does this still work? What am i doing wrong? many thanks

    http://pastebin.com/LKEihjgP

    It should be noted that i'm successfully getting my affiliate value and echoing it out on the page. it is the query that isn't working.

  2. AngelEyes
    Member
    Posted 3 months ago #

    well... i seem to have had some luck with this format-

    $args = array(
    'post_type' => 'any',
    'meta_query' => array(
    array(
    'key' => 'Affiliate',
    'value' => $affiliate,
    )
    )
    );

    it seems like wordpress wanted the query nested inside 'meta_query' even though it wasn't multiple meta values. I think this contradicts what is inside the codex. Anyways this works!

Reply

You must log in to post.

About this Topic