Advertisement
phpface

Untitled

Dec 15th, 2017
263
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.76 KB | None | 0 0
  1. if( ! function_exists( 'custom_related_widget_args' ) ){
  2.     /**
  3.      * @param array $args
  4.      * @param string $widget_id
  5.      * @return array
  6.      */
  7.     function custom_related_widget_args( $args, $widget_id ) {
  8.         $args['post_type'] = get_post_type();
  9.         $args['tax_query'] = array(
  10.             'relation'  =>  'AND',
  11.             array(
  12.                 'taxonomy' => 'category',
  13.                 'field' => 'id',
  14.                 'terms' => wp_list_pluck( wp_get_post_terms( get_the_ID(), 'category' ), 'term_id'),
  15.                 'operator'  =>  'IN'
  16.             ),
  17.             array(
  18.                 'taxonomy' => 'post_tag',
  19.                 'field' => 'id',
  20.                 'terms' => wp_list_pluck( wp_get_post_terms( get_the_ID(), 'post_tag' ), 'term_id'),
  21.                 'operator'  =>  'IN'
  22.             )
  23.         );
  24.         return $args;
  25.     }
  26.     add_filter( 'mars_related_widget_args' , 'custom_related_widget_args', 100, 2 );
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement