How to add array for post_type of post field

Support MB Builder How to add array for post_type of post field

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #7241
    yumikomyumikom
    Participant

    Hi,

    I'm trying post filed select of all post types and page.
    But post_type option have only one type.

    How to add array for post_type of post field?

    now builder generate code

    'fields' =>   array (
            
            array (
              'id' => 'nw_post',
              'type' => 'post',
              'name' => 'title-example',
              'post_type' => 'post',
              'field_type' => 'select',
              'query_args' =>       array (
                'post_type' => 'array(\'page\', \'test-custom-post-type-name\')',
              ),
            ),
          ),
    #7262
    Truong GiangTruong Giang
    Participant

    Hi there,

    There is another approach. You can use the select field and pass options as array of post types which we can retrieve via get_post_types() function.

    Thanks.

    #7270
    Anh TranAnh Tran
    Keymaster

    Hi,

    The option post_type accepts array of post types. So you can get all the post types via get_post_types() function and pass them to post_type.

    #7292
    yumikomyumikom
    Participant

    Hi,

    Thanks for your advices.

    I'm fixed. All post types seleced of post field option post_type = 'any'.
    As expected, I'd like to select some post type set to post_type with array.
    But builder post_type option select box only one post type.
    Custom Attributes no accepts array

    'query_args' => array (
        'post_type' => array('page', 'test-custom-post-type-name'),
    ),

    I'd like to use array in post_type value with MB Builder post field setting.

    #7293
    Anh TranAnh Tran
    Keymaster

    I see.

    Actually, you can use Dot notation or JSON syntax to enter array for custom attributes. For more info, please check this docs.

    #7339
    yumikomyumikom
    Participant

    Hi,

    This is the document I wanted to know.
    Thank you very much.

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘How to add array for post_type of post field’ is closed to new replies.