Replace query_posts with pre_get_posts

Without seeing the broken code it is hard to say, but your filter should look something like this:

function pregp_wpse_97354($qry) {
  if (is_front_page() && is_main_query() && is_user_logged_in()) {
    $qry->set('cat',2);
    $qry->set('posts_per_page',5);
    $qry->set('orderby','date');
    $qry->set('order','DESC');
  }
}
add_action('pre_get_posts','pregp_wpse_97354');

You mentioned something about the user being logged in, which your code does not check for, but I threw that in. This will run before the theme templates load so if this is conditional on the user being logged in you need to include that check in the filter callback.

Leave a Comment