WP_Query in args of rwmb_meta

Support General WP_Query in args of rwmb_metaResolved

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #24129
    YumikomYumikom
    Participant

    Hi,

    I want to get publish post with post_status when displaying the post field.
    https://docs.metabox.io/fields/post/

    I specified query_args in the post field, but I get all posts.

    
    $args = array(
    'query_args'  => array(
            'post_status'    => 'publish',
        ),
    );
    $posts = rwmb_meta( 'field_posts', $args, $post->ID );
    

    Is it possible to specify WP_Query in args of rwmb_meta?

    Best regards,
    Yumikom

    #24134
    YumikomYumikom
    Participant

    Hi Long,

    It would be helpful if I could use query to get the post.
    This is because post_status is very important throughout WordPress.
    I have high expectations for the future.

    Thanks and regards,
    Yumikom

    #24137
    Long NguyenLong Nguyen
    Moderator

    Hi,

    The helper function rwmb_meta() does not support argument query_args. Some field types (image, file, etc.) or extension (MB Settings Page, MB Custom Table) support passing the argument.

    If you want to get the published post only, you should create a new WP_Query and use the helper function inside the loop.

    $args = array(
        'post_type' => 'post',
        'post_status' => 'publish',
    );
    
    $my_query = new WP_Query( $args );
    while( $my_query->have_posts() ) {
        // Loop in here
        $my_query->the_post();
        $field_value = rwmb_meta( 'field_id', '', get_the_ID() );
    }
    #24146
    YumikomYumikom
    Participant

    Hi,

    There is no problem because publish is extracted from the acquired data.

    Thank you.

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.