Field type "POST" that returns post of a custom type created by the same user

Support MB Builder Field type "POST" that returns post of a custom type created by the same userResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #43426
    Salony MohantySalony Mohanty
    Participant

    hi - i want to create a custom field with type "POST"
    the drop down should show only the posts of custom post type "Funnels" created by the user
    i am not able to see anything in the wp query set up otpion for POST
    i see "author" as condition field - but when i set up the conditin to match to {current_user_id} it is not working..

    #43433
    PeterPeter
    Moderator

    Hello,

    You can use the code to register the field and get the current user then assign it to the setting query_args. For example:

    add_filter( 'rwmb_meta_boxes', 'callback_function' );
    
    function callback_function( $meta_boxes ) {
        $current_user_id = get_current_user_id();
        
        $meta_boxes[] = [
            'title'      => __( 'My Custom Fields', 'your-text-domain' ),
            'id'         => 'my_custom_fields',
            'post_types' => ['post'],
            'fields'     => [
                [
                    'id'         => 'funnel_post',
                    'title'      => 'Funnel Post',
                    'type'       => 'post',
                    'post_type'  => 'funnel',
                    'query_args' => [
                        'author' => $current_user_id,
                    ],
                ],
            ],
        ];
    
        return $meta_boxes;
    }

    Refer documentation https://docs.metabox.io/fields/post/
    https://developer.wordpress.org/reference/classes/wp_query/#author-parameters

    #43456
    Salony MohantySalony Mohanty
    Participant

    thanks worked like a charm...

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