Support

Search results for ""

Sorry, no results found. Perhaps you would like to search the documentation?
All Topics
Nadav

Hiding "has/without" options in filters

Hello,

When I enable a column to be filtered, I get two extra lines at the end of the filter which I do not want. In the case of a taxonomy it would say “without taxonomy” and “has taxonomy”. How do I get rid of those?

Thanks!

6 years, 1 month ago
Stefan van den Dungen Gronovius
Developer

Hi Nadav,

The only way to do this is to use our hook acp/filtering/dropdown_args.
The following example shows you how you can remove the empty and not empty in the filtering dropdowns for the specific taxonomy column, but you can do this for each column or for other specific columns.

/**
 * Hide empty option from filter menu
 *
 * @param array     $args
 * @param AC_Column $column
 *
 * @return array
 */
function my_ac_filter_menu_remove_empty_options( $args, $column ) {

	if ( 'column-taxonomy' === $column->get_type() ) {
		$args['empty_option'] = false;
	}

	return $args;
}

add_filter( 'acp/filtering/dropdown_args', 'my_ac_filter_menu_remove_empty_options', 10, 2 );

You can find the documentation for this filter on our website:
https://www.admincolumns.com/documentation/filter-reference/acp-filtering-dropdown_args/

6 years, 1 month ago
Nadav

Hi,

I tried this in more than form without success. I used the code you provided (its cleaner version straight from one of your links), as well as another code that’s on the links you sent:

/**
* Hide empty option from filter menu
*
* @param array $args
* @param AC_Column $column
*
* @return array
*/
function my_ac_filter_menu_remove_empty_options( $args, $column ) {

$column_type = ‘column-meta’;

if ( $column_type === $column->get_type() ) {

if ( isset( $args[’empty_option’] ) ) {
unset( $args[’empty_option’] );
}
}

return $args;
}

add_filter( ‘acp/filtering/dropdown_args’, ‘my_ac_filter_menu_remove_empty_options’, 10, 2 );

In both cases, I replaced “column-type” (or “column-taxonomy”) with the name of the custom fields (“regions”) as well as with the unique acp filter id: acp-filter-5aa0c56e2fda3 . No luck in either case. What am I doing wrong?

Thanks,
Nadav

6 years, 1 month ago
Nadav

Ok, I think I got it. Without replacing any code (unlike what I thought I had to do), the function does remove the with/without taxonomy. How do I control then for it to work on specific columns and not on others? Or, have the function run on everything and exclude (=display with/without) only on certain columns?

6 years, 1 month ago
Stefan van den Dungen Gronovius
Developer

Hi nadav,

Yes, the example I send you only removed the empty options for the Taxonomy columns. I thought you wanted to do this only for the taxonomy column, based on your first message. But yes, you can check for every column since you have the $column variable at your disposal. I will give you some example conditions below.

// Check for a Custom Field and check for a specific custom field key
if ( $column instanceof ACP_Column_CustomField && 'regions' === $column->get_meta_key() ) {}
// Check for all custom field columns
if ( 'column-meta' == $column->get_type() ) {}
// Check for all Taxonomy columns. The type of a column can be found when you inspect the td where the value is displayes. You could could inspect the drop down for type on our settings page
if ( 'column-taxonomy' == $column->get_type() ) {}
6 years, 1 month ago

You must be logged in to reply to this topic.