By Post Field 'query args' with author

Support General By Post Field 'query args' with authorResolved

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #13586
    cruz@assima.de[email protected]
    Participant

    Hello

    I want to filter a Post Select with the actually author...

    array(
                'name'        => 'Firma auswahlen',
                'id'          => 'trainer_firma',
                'type'        => 'post',
    
            // Post type.
            'post_type'   => 'per_trainer_firmen',
    
            // Field type.
            'field_type'  => 'select_advanced',
    
            // Placeholder, inherited from <code>select_advanced</code> field.
            'placeholder' => 'Firma auswahlen',
    
                // Query arguments. 
                'query_args'  => array(
                    'post_status'    => 'publish',
                    'posts_per_page' => - 1,
                    'author'    => ???authorID???,
    
                ),
            ),

    'query args' for author... If I try to write 'author' => 1, works fine... But I want to do this for any Authors...

    I think: get_current_user_id();
    But this is not working...

    can you help me?

    Thank you!

    #13605
    Anh TranAnh Tran
    Keymaster

    Do you mean query posts created by current user? Please clarify which user you want to set as author.

    #13621
    cruz@assima.de[email protected]
    Participant

    Hi Anh

    "Do you mean query posts created by current user?"

    Yes!

    🙂

    #13635
    Anh TranAnh Tran
    Keymaster

    I think the problem is calling get_current_user_id too early. This docs page has an interesting comment:

    Before the plugins_loaded action it returns 0.

    So you might want to make some change to:

    add_action( 'init', function() {
         add_filter( 'rwmb_meta_boxes', 'your_register_function' );
    } );
    #13759
    cruz@assima.de[email protected]
    Participant

    Hello Anh

    Can you show me, what I have to do?
    I have not understand, what I have to change... 🙁

    Thank you Anh

    #13771
    Anh TranAnh Tran
    Keymaster

    Assume you have this code to register your meta box:

    add_filter( 'rwmb_meta_boxes', 'prefix_register_meta_boxes' );
    function prefix_register_meta_boxes( $meta_boxes ) {
        $meta_boxes[] = array(
            // Your meta box code goes here
        );
    }

    Then change it to:

    add_action( 'init', function() {
         add_filter( 'rwmb_meta_boxes', 'prefix_register_meta_boxes' );
    } );
    function prefix_register_meta_boxes( $meta_boxes ) {
        $meta_boxes[] = array(
            // Your meta box code goes here
        );
    }
    #13816
    cruz@assima.de[email protected]
    Participant

    Thank you!

    #46534
    Kilian GötzKilian Götz
    Participant

    Hey I got the same problem but I registered the Custom Field that contains the Post Field that I want to quary arg for the author = user with your MetaBox AIO Plugin and the GUI

    I dont know where i have to put those i register the metabox with your plugin

    Assume you have this code to register your meta box:

    add_filter( 'rwmb_meta_boxes', 'prefix_register_meta_boxes' );
    function prefix_register_meta_boxes( $meta_boxes ) {
    $meta_boxes[] = array(
    // Your meta box code goes here
    );
    }

    Then change it to:

    add_action( 'init', function() {
    add_filter( 'rwmb_meta_boxes', 'prefix_register_meta_boxes' );
    } );
    function prefix_register_meta_boxes( $meta_boxes ) {
    $meta_boxes[] = array(
    // Your meta box code goes here
    );
    }

    #46535
    Kilian GötzKilian Götz
    Participant

    i use the shortcode for frontend submission where do i have to put your code if i still want to use the shortcode?

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