Support Forum
Support › MB Custom Table › Filterin select advanced with custom field in custom tableResolved
Hello,
I want to select_advanced field, but only get the users that meet a condition with respect to a proper field saved in custom table users.
$meta_boxes[] = [
//'title' => '',
'id' => 'id_field_metabox',
'type' => 'user',
'storage_type' => 'custom_table', // Important
'table' => 'usuarios', // Your custom table name
'fields' => [
[
'id' => 'id_field_metabox_select',
'name' => '',
'type' => 'user',
'multiple' => true,
'field_type' => 'select_advanced',
'query_args' => array(
'meta_key' => 'custom_field_A',
'meta_value' => '0',
),
],
],
I try this:
'query_args' => array(
'meta_key' => 'custom_field_A',
'meta_value' => '0',
),
But not run: "No results found".
Where custom_field_A was created before:
[
'id' => 'custom_field_A',
'name' => 'Custom Field A',
'type' => 'text',
'std' => 0, // 0 or 1',
],
];
It's possible this?
Many thanks,
Sergio
Hi Sergio,
The meta_key
and meta_value
in the query_args
will tell the plugin to filter users by WordPress custom fields, e.g. user meta. They don't handle the value in the custom table.
Oh, thanks, I understand.
So I do not know if it can be done or if in this forum you could guide me for the following:
To obtain in the results of the select_advanced the users of a custom table related to the users according to a condition that occurs on a field saved in the custom table itself.
Thanks
Hi Sergio,
I think that can be done with an extra query to the data base:
global $wpdb;
$user_ids = $wpdb->get_col( "SELECT ID FROM yourtable WHERE field_1 = 'value_1'" );
user
field, set the include
param:[
'type' => 'user',
'query_args' => [
'include' => $user_ids, // get from above
],
]
Perfect!! Many thanks!!