pass parameters through variable to WP_QUERY

0 views
0

I’m trying to use the plugin PrivateContent to limit access to certain pages/categories. I have a function (getAllowedCategories()) which reads PrivateContent access levels for the current user and outputs a list of category IDs which the user has access to. I’m trying to use this to build a foreach() loop that passes each ID to a WP_QUERY and generates the latest two posts in that category. But when I try to use a variable as WP_QUERY’s parameter, it does no filtering at all. Here is my code:

<?php

$currentCats = getAllowedCategories($user_data);
foreach ($currentCats as $currentCat) { 
    echo $currentCat . "<br/>";
    $parameters = "'category__in=" . $currentCat . "'";
    $aj_query = new WP_Query( $parameters );

    if ( $aj_query->have_posts() ) {
        echo '<ul>';
        while ( $aj_query->have_posts() ) {
            $aj_query->the_post();
            echo '<li>' . get_the_title() . '</li>';
        }
        echo '</ul>';
    }
    wp_reset_postdata();
}
?>