And why do you think it should do anything else?
What you do is:
-
You add your filter to modify default WordPress query, which is run on index page. Your modifications are correct – this query will select published root pages.
-
Then you run
get_posts
with default set of params (see below) and loop through them.
Default params for get_posts
:
$args = array(
'posts_per_page' => 5,
'offset' => 0,
'category' => '',
'orderby' => 'post_date',
'order' => 'DESC',
'include' => '',
'exclude' => '',
'meta_key' => '',
'meta_value' => '',
'post_type' => 'post',
'post_mime_type' => '',
'post_parent' => '',
'post_status' => 'publish',
'suppress_filters' => true );
You should use default WordPress loop, if you already modified default query. So do it like this:
// this will iterate posts already selected by WordPress with its default query (modified with your filter)
while ( have_posts() ) {
the_post();
echo "<li><a href="". the_permalink() ."">". the_title()."</a></li>";
}