WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Multiple specific posts using wp_query and post__in array - EXPLAINED (1 post)

  1. ixwa
    Member
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic