Can “Recent Posts” widget be filtered by functions.php?

I have my own “Recent Posts” menu, but its not currently implemented as a Widget. I’m just including it in sidebar.php.

I had to “roll my own” so to speak in order to filter the menu of certain categories whose posts I don’t want to appear in the menu.

Read More

Would it be possible, via functions.php, to filter the default “Recent Posts: widget’s menu items in order to exclude posts belonging to a specific category?

If so, I’d really be grateful for an example.

Related posts

Leave a Reply

2 comments

  1. Since WordPress 3.4.0, it’s possible to filter the argument to the query.

    add_filter('widget_posts_args', 'wpse_30124');
    
    function wpse_30124(){
      return array(
        'posts_per_page'      => $number,
        'no_found_rows'       => true,
        'post_status'         => 'publish',
        'ignore_sticky_posts' => true,
        'cat' => '-12' // term_id of the category you want to exclude
      );
    }
    

    More info class-wp-widget-recent-posts.php