I am developing a blog where the main posts are of a custom post type.

Let's assume it is a Book custom post type.

I want the /author/admin page to list the books of the author admin, but instead, it goes and searches for Posts of admin, which is the built-in basic post type.

How do I make my custom post type Book to be used in all such index queries? (main page, author, search, etc).


You can modify all main queries before they happen via the pre_get_posts action and a check if is_main_query:

function wpa75492_post_type_query( $query ) {
    if ( $query->is_main_query() ) {
        $query->set( 'post_type', array( 'book' ) );
add_action( 'pre_get_posts', 'wpa75492_post_type_query' );

use the parameter post_type=your-custom-post-type-slug-here

for example if your post type slug is "product" then use the code like:

  • Additionally if you want to keep default post types too use: [code] global $wp_query; $args = array_merge( $wp_query->query_vars, array( 'post_type' => 'product' ) ); query_posts( $args ); [/code] more details: codex.wordpress.org/Function_Reference/query_posts – Shaon Dec 9 '12 at 18:40
  • 1
    I strongly advise against the use of query_post, it causes more problems than its worth, Milo's answer demonstrates the correct alternative to query_post – Tom J Nowell Dec 9 '12 at 19:09

You need to query the posts from that specific post type before the loop. So, on your author archive page, or any page template, add this before the loop:

    'post_type'   => 'book_posttype',
    'author_name' => 'mark'

Query_posts can take other parameters as well.


It can use the same parameters as WP_query. One of which is author_name.


You can also add an author page template which you will place this query in and the loop. It would be a page in your theme directory called, author-mark.php or whatever the name is.

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.