Displaying several specific pages using WP_Query()

If you look at the query object after those queries are run, you’ll see that none of those examples are doing what you think they’re doing. The first issue is that you can’t mix query string and array parameters, and the second issue is that pagename can only be used to load a single page.

In this one, you’re missing a closing quote after pagename. Assuming this is a typo, the problem is noted above – it’s looking for a single page with slug famousmschief

$args = array(
'post_type' => 'page',
'pagename => 'famous,mschief',
'posts_per_page' => 3
);

In this one, pagename is being ignored and it’s just querying for the most recent page using the default posts per page value, which would appear to be 1.

$args = array(
'post_type' => 'page',
'pagename=famous,mschief',
);

In this one, same issue as last, but you’re loading more pages, so it’s just loading the three most recent pages:

$args = array(
'post_type' => 'page',
'pagename=famous,mschief',
'posts_per_page' => 3
);

If you want to query multiple pages, use the post__in argument, and the page IDs:

$args = array(
    'post_type' => 'page',
    'post__in' => array( 23,42 )
);

Leave a Comment