Reputation: 706
I have a post_type called books, which has custom fields for author name, publisher name, etc.
I want to create pages where publisher or authors are grouped. For example, "Penguin" or "McGraw Hill". When a user clicks on "Penguin" out of the Publisher dropdown, she should see all the books by Penguin for example.
To do this, I want to try a query like this:
$args = array(
'meta_key' => 'publisher'
,'meta_key_value' => 'Penguin'
,'taxonomy' => 'book'
,'orderby' => 'date'
,'posts_per_page' => 48
,'paged' => get_query_var('page')
);
$my_query = new WP_Query( $args );
My question is: where should I put this query? In the "category.php" or "archive.php"? And what will the link in the header look like?
Thanks!
Upvotes: 0
Views: 325
Reputation: 11980
Neither. You should put this in 'archive-book.php'. You can generate your link using get_post_type_archive_link and your link (without pretty permalinks) will look like '?post_type=book'.
You should also set up your query like so:
$args = array(
'meta_key' => 'publisher',
'meta_key_value' => 'Penguin',
'post_type' => 'book',
'orderby' => 'date',
'posts_per_page' => 48,
'paged' => get_query_var('page')
);
$my_query = new WP_Query( $args );
'book' in your case is not a Taxonomy, but rather a Custom Post Type. Let me know if this helps.
Upvotes: 1