• Resolved ixwa

    (@ixwa)


    This is a placeholder solution snippet for anyone who encountered the same problem I did.

    This DOES NOT work:

    function doProduct($allTypes) {
    //Where $allTypes is a string "1, 2, 3, 4"
    
    $args = array(
    'post_type' => 'product',
    'categories'	=> 'misc',
    'post_status' =>	'publish',
    'post__in' => array($allTypes)
    );
    
    ...
    }

    So even though $allTypes is a literal string “1, 2, 3, 4” that would look EXACTLY like what you might have typed into the array yourself, it doesn’t work.

    This DOES work:

    function doProduct($allTypes) {
    //Where $allTypes is a string "1, 2, 3, 4"
    
    $args = array(
    'post_type' => 'product',
    'categories'	=> 'misc',
    'post_status' =>	'publish',
    'post__in' => explode(',', $allTypes)
    );
    
    ...
    }

    Don’t ask me why. Another reason why WordPress is more like KlugePress…or maybe it’s just screwy PHP.

  • The topic ‘Multiple specific posts using wp_query and post__in array – EXPLAINED’ is closed to new replies.