Filter
time_based_menu_rpress_categories
On this page
Filters the list of menu categories shown in the category navigation.
Applied to the categories returned by rpress_get_categories() (or rpress_get_child_cats() when a category menu is configured) before the category list is rendered. It is used in the sidebar category list, the scrollable category bars and the mobile category menu. The shortcode attribute data is passed as the second argument so callbacks can adapt to the menu being displayed.
Parameters#
| Parameter | Type | Description |
|---|---|---|
$get_all_items | array|WP_Error | Terms of the food-category taxonomy as returned by get_terms(). |
$data | array | Menu shortcode data for the current menu, including the ids, category_menu and excluded_category keys. |
Return value#
array. The list of category terms to display.
Example#
add_filter( 'time_based_menu_rpress_categories', 'my_hide_empty_cat_list', 10, 2 );
function my_hide_empty_cat_list( $get_all_items, $data ) {
if ( ! is_array( $get_all_items ) ) {
return $get_all_items;
}
return array_values( array_filter( $get_all_items, function ( $term ) {
return $term->slug !== 'specials';
} ) );
}
Notes#
The name suggests time-based menus, but the filter runs for every menu render. The first argument can be a WP_Error if get_terms() failed, so check its type before iterating.
Source#
Applied in:
templates/grid/scrollable-categories-mobile.php(line 20)templates/grid/scrollable-categories.php(line 20)templates/list/scrollable-categories.php(line 21)templates/packs/modern/rpress-get-categories.php(line 25)templates/rpress-get-categories.php(line 19)templates/rpress-mobile-menu-category.php(line 17)
See also#
Was this page helpful?
