On the Reading Settings page I have clicked Your latest posts under Front page displays. I am wondering how I can filter the query that displays these posts before it gets to the loop.

I have tried to use the pre_get_posts filter but that does not seem to have access to this query.

Is there anyway to modify the posts being displayed on the front/home page by editing functions.php and not messing around with template files?

link|improve this question
feedback

2 Answers

    <?php global $query_string; ?>
    <?php if (is_home())
                query_posts($query_string . 'order=DESC&orderby=modified'); 
    ?>

Try the above code in your index.php.

Put it just above:

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
link|improve this answer
feedback

How are you using it?

Here's a example:

add_filter('pre_get_posts', 'change_query');

funnction change_query($query){
   // if(is_front_page())
   $query->set('orderby', 'comment_count');
   // see: http://codex.wordpress.org/Class_Reference/WP_Query

   return $query;
}
link|improve this answer
I am using it just like you have shown above. This filter does not seem to fire for the latest posts. – Mike Jul 6 '11 at 22:12
still an issue i think. tested w/ wp3.3.1 and pre_get_posts() doesn't seem to take effect on the Your Latest Posts page – helgatheviking Jan 12 at 20:58
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.