- Define the acf key
- grab the choices
- create a select with choices
- request on the meta key/meta value
Created
May 14, 2015 11:14
-
-
Save jackabox/a2b48c780908adbda4bc to your computer and use it in GitHub Desktop.
Filtering custom post types by an ACF field.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function my_restrict_manage_posts() { | |
global $typenow; | |
if ($typenow == 'adtrak_applicants'){ | |
$field_key = "field_553fafc094dc6"; | |
$field = get_field_object($field_key)['choices']; | |
?> | |
<select name="adtrak_applicants_filter"> | |
<option value=""><?php _e('All statuses', 'adtrak_applicants'); ?></option> | |
<?php | |
$current_v = isset($_GET['adtrak_applicants_filter']) ? $_GET['adtrak_applicants_filter'] : ''; | |
foreach ($field as $label => $value) { | |
printf ( | |
'<option value="%s"%s>%s</option>', | |
$value, | |
$value == $current_v? ' selected="selected"':'', | |
$label | |
); | |
} | |
?> | |
</select> | |
<?php | |
} | |
} | |
add_action('restrict_manage_posts','my_restrict_manage_posts'); | |
function request_applicant_filter($request) { | |
if (is_admin() && isset($request['post_type']) && $request['post_type']=='adtrak_applicants') { | |
$request['meta_key'] = 'status'; | |
$request['meta_value'] = $_GET['adtrak_applicants_filter']; | |
} | |
return $request; | |
} | |
add_action( 'request', 'request_applicant_filter' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment