views:

63

answers:

1

I'm creating a Wordpress plugin and, being a newbie in the development on this platform, I'm stuck on this problem.

I'd like to have posts in the loop filtered by categories, defined by the user through an admin page. I would actually like to be able to modify query_post() parameters in the plugin, but the only trick I found is to re-run the query_post() with my user-defined criteria, thing that I would like to avoid.

Also, due to the plugin nature, I think it make no sense to modify the theme's template.

I'm sure the solution is evident, but can't find it!

A: 

I thought there was a nicer solution, but this is how I finally solved it:

add_filter ( 'query_vars', 'myplugin_filter_posts');

function myplugin_filter_posts( $content )
{
  //WP's query handler
  global $wp_query;

  //The id of the category whose posts I'd like to show
  $catId = 1;

  $result = $wp_query->query( 'cat='.$catId );
  return $content;
}

If you tips for a better solution, please share :)

Davide