• Resolved robahas

    (@robahas)


    Hi – I am using the following to generate a list of posts that have certain tags:

    $query = array('cat' => '4', 'orderby' => 'rand', 'tag__in' => array(7,9))

    This works great.

    The problem is that I can’t seem to generate the array for tag__in dynamically. If I use an array of values ( ‘tag__in’ => $array )it always outputs thus:

    [tag__and] => Array ( [0] => 7,9 )

    But the query wants only values separated by commas. Because of this it only recognizes the first tag.

    So how do I make an array only output comma separated values without keys? (PS I tried implode() and got the same result).

    Thanks!

Viewing 1 replies (of 1 total)
  • Thread Starter robahas

    (@robahas)

    Here’s how I got it working:

    $tags = '1,2,3';
    $tags = explode(',',$tags);
    $post_query = array('cat' => '4', 'orderby' => 'rand', 'tag__in' => $tags );
    query_posts($post_query);

    Here’s what $post_query looks like:

    Array ( [cat] => 4 [orderby] => rand [tag__in] => Array ( [0] => 7 [1] => 9 ) )

    Maybe it will help someone.

Viewing 1 replies (of 1 total)
  • The topic ‘Using an array in query_posts’ is closed to new replies.