By Post Field 'query args' with author
- This topic has 8 replies, 3 voices, and was last updated 6 months, 4 weeks ago by
Kilian Götz.
-
AuthorPosts
-
March 7, 2019 at 1:47 AM #13586
[email protected]
ParticipantHello
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!
March 7, 2019 at 11:43 PM #13605Anh Tran
KeymasterDo you mean query posts created by current user? Please clarify which user you want to set as author.
March 8, 2019 at 9:35 PM #13621[email protected]
ParticipantHi Anh
"Do you mean query posts created by current user?"
Yes!
🙂
March 10, 2019 at 8:12 AM #13635Anh Tran
KeymasterI 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' ); } );
March 16, 2019 at 4:10 PM #13759[email protected]
ParticipantHello Anh
Can you show me, what I have to do?
I have not understand, what I have to change... 🙁Thank you Anh
March 18, 2019 at 11:51 AM #13771Anh Tran
KeymasterAssume 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 ); }
March 20, 2019 at 6:44 PM #13816[email protected]
ParticipantThank you!
September 26, 2024 at 1:14 AM #46534Kilian Götz
ParticipantHey 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
);
}September 26, 2024 at 1:58 AM #46535Kilian Götz
Participanti use the shortcode for frontend submission where do i have to put your code if i still want to use the shortcode?
-
AuthorPosts
- You must be logged in to reply to this topic.