I am trying to:
I have a Post Type called Grant Applications. Two fields in the post type are called app-reviewer-1 and app-reviewer-2. When I build a View to list the posts with filters for Reviewer 1 and Reviewer 2 they aren't working. The filters are empty.
There is custom code which populates the values for the post fields app-reviewer-1 and app-reviewer-2. Below is the code.
/**
* Auto-populate custom Reviewer Fields
*/
add_filter( 'wpt_field_options', 'sc_populate_reviewer1_field', 10, 2 );
function sc_populate_reviewer1_field( $current_options, $title_of_field ){
if ('Reviewer 1' == $title_of_field ) {
$current_options = array();
$args = array(
'role' => 'author',
'orderby' => 'user_nicename',
'order' => 'ASC'
);
$users = get_users( $args );
foreach ( $users as $user ) {
$current_options[] = array(
'#title' => $user->display_name,
'#value' => $user->ID
);
}
}
return $current_options;
}
add_filter( 'wpt_field_options', 'sc_populate_reviewer2_field', 10, 2 );
function sc_populate_reviewer2_field( $current_options, $title_of_field ){
if ('Reviewer 2' == $title_of_field ) {
$current_options = array();
$args = array(
'role' => 'author',
'orderby' => 'user_nicename',
'order' => 'ASC'
);
$current_options[] = array(
'#title' => '- none -',
'#value' => 0
);
$users = get_users( $args );
foreach ( $users as $user ) {
$current_options[] = array(
'#title' => $user->display_name,
'#value' => $user->ID
);
}
}
return $current_options;
}
Here is how the filters are defined in the View
[wpv-filter-start hide="false"]
[wpv-filter-controls]
<div class="form-group">
<label>[wpml-string context="wpv-views"]Grant Year[/wpml-string]</label>
[wpv-control-postmeta field="wpcf-grant-year-select" url_param="wpv-wpcf-grant-year-select"]
</div>
<div class="form-group">
<label>[wpml-string context="wpv-views"]Reviewer 1[/wpml-string]</label>
[wpv-control-postmeta field="wpcf-app-reviewer-1" url_param="wpv-wpcf-app-reviewer-1"]
</div>
<div class="form-group">
<label>[wpml-string context="wpv-views"]Reviewer 2[/wpml-string]</label>
[wpv-control-postmeta field="wpcf-app-reviewer-2" url_param="wpv-wpcf-app-reviewer-2"]
</div>[/wpv-filter-controls]
[wpv-filter-end]
You can see this problem at this link.
hidden link
Hi,
The "wpt_field_options" filter hook works for custom select/radio field in wordpress admin side when you edit/create a post, it won't work in the custom search form of Views plugin.
So there isn't such a feature within Views plugin, you can submit a feature request for it:
https://toolset.com/forums/forum/professional-support/#feature-request
Our developers will evaluate it, but there isn't any ETA for it.
If your author users are not too much, you can manually setup the options of select field in custom search form, see screenshot: select1.jpg