admin管理员组

文章数量:1278854

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;

    endif;

}

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.

本文标签: wp queryCreate if else for post types in WPQuery 39postin39 values