Support Forum
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!
Do you mean query posts created by current user? Please clarify which user you want to set as author.
Hi Anh
"Do you mean query posts created by current user?"
Yes!
🙂
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' );
} );
Hello Anh
Can you show me, what I have to do?
I have not understand, what I have to change... 🙁
Thank you Anh
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
);
}
Thank you!
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
);
}
i use the shortcode for frontend submission where do i have to put your code if i still want to use the shortcode?