Custom Fields
Re-Envisioned
Support General WP_Query in args of rwmb_meta

  • Creator
    Topic
  • #24129
    Resolved Yumikom
    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

Viewing 3 replies - 1 through 3 (of 3 total)
  • Author
    Replies
  • #24134
    Yumikom
    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 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
    Yumikom
    Participant

    Hi,

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

    Thank you.

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