add a filter to a sidebar widget ,wordpress posts_per_page

Hi Im wondering how to alter the number of posts_per_page. The widget() function in default-widgets.php contains this line..

$r = new WP_Query( apply_filters( 'widget_posts_args', array( 'posts_per_page' => $number, 'cat' => 1, 'no_found_rows' => true, 'post_status' => 'publish', 'ignore_sticky_posts' => true ) ) );

The variable $number is set right before this line as 10 but I would rather insert my own filter for posts_per_page and change it to 1.

But Im unsure how to add a filter to this, im only learning about hooks and filters at the moment. As far as I know there is an array with posts_per_page but I dont know how to change this.

function recent_post_count() {
$query->set('posts_per_page', 1);
add_filter( 'widget_posts_args', 'recent_post_count', 6); 


You're using the wrong argument.

function recent_post_count($args) {
  $args['posts_per_page'] = 5;
  return $args;
add_filter( 'widget_posts_args', 'recent_post_count'); 

Need Your Help

Application configuration files

java xml json cross-platform configuration-files

OK, so I don't want to start a holy-war here, but we're in the process of trying to consolidate the way we handle our application configuration files and we're struggling to make a decision on the ...

Find out output of c-program



About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.