Add select filter based on acf field to custom post type in dashboard

Good morning everyone;

I am trying to add a select filter like this:
Select filter based on taxonomy

To do this, I am getting all field values like:
Display all select field values

I am able to display select values, but filter is not working.
Does anyone know how to solve it?

My code:

function filter_retiros_by_categories( $post_type, $which ) {
if ( ‘retiro’ !== $post_type )
return;

$campos = array( ‘Categorías’ => ‘field_5cae2d856c508′ );

foreach ( $campos as $key_campo => $campo ) {
$obj = get_field_object($campo);

echo “<select name='{$campo}’ id='{$campo}’ class=’postform’>”;
echo ‘<option value=””>’ . $key_campo . ‘</option>’;

if( $obj[‘choices’] ):
foreach( $obj[‘choices’] as $value):
echo ‘<option value=”‘ . $value . ‘”>’ . $value . ‘</option>’;
endforeach;
endif;

echo ‘</select>’;
}

}

add_action( ‘restrict_manage_posts’, ‘filter_retiros_by_categories’ , 10, 2);

I know I am using an array to display only one select. I want to include more fields when get this working.

Thanks in advance!

Read more here:: Add select filter based on acf field to custom post type in dashboard

Leave a Reply

Your email address will not be published. Required fields are marked *