Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

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;
}
share|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 '12 at 20:58
    <?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(); ?>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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