Advertisement
fauzanjeg

Filter content for categories widget

Jun 20th, 2021
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.59 KB | None | 0 0
  1. /** Filter content for categories widget */
  2. function widget_categories_args_filter( $cat_args ) {
  3.     $categories_name = array( 'apps', 'entertainment' );
  4.     $include_arr = array();
  5.  
  6.     foreach ($categories_name as $data) {
  7.         $include_arr[] = get_cat_ID( $data );
  8.     }
  9.  
  10.     if ( isset( $cat_args['include'] ) && ! empty( $cat_args['include'] ) ) {
  11.         $include_arr = array_unique( array_merge( explode( ',', $cat_args['include'] ), $include_arr ) );
  12.     }
  13.     $cat_args['include'] = implode( ',', $include_arr );
  14.     return $cat_args;
  15. }
  16. add_filter( 'widget_categories_args', 'widget_categories_args_filter', 10, 1 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement