1

I have to display 12 items of my custom post type on the front page of my theme. However, when I do this, the page title (<title>...</title>) changes to Custom Post Type archive - Page Title.

Since this is the front page, I just want this to have the normal frontpage title, namely Page title - page tag line. Is there any way to set this variable in the new query_posts()? Or to just prevent that the page title changes, when using a new query_posts()?

I don't mind this happening on sub-pages and such, but on the front page, it shouldn't change when I filter resutls on post_type.

This is the query I use right now:

query_posts( array( 
   'post_type' => 'bwps',
   'posts_per_page' => 12
));
3

You shouldn't be using query_posts() at all. From the documentation:

Note: This function will completely override the main query and isn’t intended for use by plugins or themes. Its overly-simplistic approach to modifying the main query can be problematic and should be avoided wherever possible. In most cases, there are better, more performant options for modifying the main query such as via the ‘pre_get_posts’ action within WP_Query.

If you want to show some custom posts on your front page, then you should create a template for the front page (either front-page.php or a custom template. Then, on that template, query for those posts with your own WP_Query:

$bwps = new WP_Query( array( 
   'post_type' => 'bwps',
   'posts_per_page' => 12
) );

And loop through them with the query methods on $bwps:

if ( $bwps->have_posts() ) :
    while ( $bwps->have_posts() ) : $bwps->the_post();
        the_title();
    endwhile;
endif;

If you want to keep Your home page displays set to Your latest posts, and to keep pagination on the home page, just replacing those latest posts with your own post type, then see this previous question on the topic.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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