I'm trying to enable users to select individual posts by custom post type using a new WP_Query

$posts = new WP_Query( array(
        'post__in'       => selected_posts(),
        'post_type'      => $post_types,
    ) );

And using a custom function based on user selection but its not working

function selected_posts() {

    $post_in = get_post_meta( get_the_ID(), 'post_in', true );

    $page_in = get_post_meta( get_the_ID(), 'page_in', true );

    $custom_post_type_in = get_post_meta( get_the_ID(), 'custom_post_type_in', true );

    if ( $custom_post_type_in == 'true' ) :

    $show = $custom_post_type_in;

    elseif ( $page_in == 'true' ) :
    $show = $page_in;

    else :
    $show = $post_in;



The value for post__in parameter should be shown when a specific post type is selected including post, page and cpt and only posts selected for that post type should be shown using the 'post__in' parameter.

  • Is the array return missing?
    – birgire
    Nov 2 at 11:33
  • @birgire No i tried adding return $show but not working.
    – Dev
    Nov 2 at 11:45
  • Try return array( 123, 321 ); and then expand on that. Most likely your meta is storing string. Check the type/value of all your variables.
    – birgire
    Nov 2 at 12:21
  • @birgire No i want to return the value for each post id selected from the multi select drop down menu and then add that to the value for ''post__in' in WP_Query
    – Dev
    Nov 2 at 13:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.