You shouldn’t use query_posts functions. You should create instance of WP_Query class
In your theme folder create a new file called category-slug.php. You can copy the category.php file or archive.php file to create category-slug.php file.
Then in the new category-slug.php file before the while loop you can write your query.
$query = new WP_Query( 'category_name=apple,pears' );
<?php if ( $the_query->have_posts() ) : ?>
<!-- pagination here -->
<!-- the loop -->
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php endwhile; ?>
<!-- end of the loop -->
<!-- pagination here -->
<?php wp_reset_postdata(); ?>
<?php else : ?>
<p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
<?php endif; ?>
You might need to replace your existing while statement with this one.
Related Posts:
- Using meta_query, how can i filter by a custom field and order by another one?
- Adding content to archive and taxonomy pages on custom post types?
- Filtering a custom post type by custom taxonomy in archive template
- get term archive url / link
- How to get the custom post type from an archive page?
- $query->set in pre_get_posts is unintentionally affecting the backend
- Pagination throws 404 error on custom taxonomy archive pages
- Custom Post Type Archive Page: Set Posts Per Page, Paginate
- Custom Post Type Archives with 0 Posts Redirects as 404
- Archive page with multiple taxonomies rewrite
- Archive page…limiting posts per page
- WP 3.1 – archive pages for custom content types possible now without a plugin?
- Display Custom Post Type Fields
- Custom Post Type Archive URL takes over page URL
- How to Add Pages Under Custom Post Type URL Structure?
- Posts per Page on custom Taxonomy Template
- How to get the parent’s taxonomy?
- Include Custom Posts Type in Year/Month/Date Archive
- where can I see my custom post type archive template?
- ascending order custom post type
- Query not returning CPT posts
- Post Rank on Single Post page based on custom field
- Call different archive page based on post type
- How to get only one category of custom post type?
- Unable to display multiple post types in same query (WPML WP_Query)
- How to display recent posts added in several custom post types
- Custom Post Types and archives
- query_posts with a custom post type, a meta_query and sorting by post date?
- Custom query shows custom post types in trash
- How to get “custom post type”-archive with working permalink to it?
- Combine query_posts() and get_posts() into single query
- how can i get posts from custom post type particular taxonomy category
- Custom template page with custom archives listing by user
- Query/list all terms and their custom post count
- Root slug of taxonomy returning 404
- How to modify archive query with pre_get_posts to append CPTs?
- Display only one post each WEEK
- get custom post type
- Change CPT archive title
- Polylang non-default language ignores tags in WP_Query
- The loop seems stuck to a single (now deleted) post
- Use “archive” as slug for custom post type
- Limit the post for differents custom post type in the same wp_query
- Custom post type archive page for multiple post types
- Custom post type posts don’t show in archive widget
- Archive for a Taxonomy of a Custom Post type
- Filter date from post meta when date is in string format
- Problems with 404, .htaccess, permalinks and WordPress custom posts locally on Snow Leopard
- Custom query – get_the_terms not work
- Return the name of the post type
- 3 random images from custom post type, each in a div with a diffrent class
- Set a hard-coded page-template (post-type-archive) as home/front-page of my wordpress blog?
- why is the current page title being output?
- Not able to export large no. of posts in csv
- archive as a page, so that it can be added in the wp_menu_nav
- Targeting custom post type via functions.php doesn’t work
- Archive links for custom post types
- Show All Custom Post Types On A Single Archive Page
- Custom Post Type Archive Pagination
- Need to have an archive widget which organizes and displays a custom post type using a custom date field
- Archive Template being used instead of Category Template for Custom Post Type
- pre_get_posts works in post type archive but not in single post
- 4 posts per page from single category
- Menu’s breaking, now showing all page links on site
- Display Posts Query with IF function
- Getting custom post type info using get_adjacent_post
- How can I allow users to edit text that will be displayed on a custom post type archive page?
- How can I increase the post count for custom post types only?
- Query for bbPress replies to current topic?
- Why can’t I query more than 1 post type at a time?
- Is possible register two archive pages for single custom post type?
- WP query_posts group by meta field related
- users post count
- custom post type and a “sticky” position taxonomy
- Custom Post Type Archive Page showing as 404
- Order Posts in Custom Order
- Custom Post Type archive page listing a 404 or single post
- The page or ad listing you are trying to reach no longer exists or has expired
- One of my headings is mysteriously coming up as a link in my CPT Archive
- Query the title of the page to show posts with matching category in the loop
- I broke it! Custom post type archive gets redirected to home
- How to Create movie schedule by custom post type query
- Main site single-property.php design, as homepage of a multisite
- Custom nav menu current item custom link problem
- How to get main div html to print a list of posts inside?
- Stop Custom post type from being searched via URL
- archive-{custom_post_type}.php not getting recognized wordpress
- Using $seed on a custom post type for randomly displayed posts
- Custom Post Types Archives and daily/monthly joke
- Display results from two Custom Post Types in page template
- What’s the best way to show custom post types? With page template it’s not perfect!
- How to make a list of posts displaying them 5 by 5 with a “next posts” link?
- Query Custom Post Type and sort by year
- How to grab data (titles, thumbnails and custom fields) from multiple posts to populate a new array efficiently?
- Pagination not working for archive
- How do I correctly query posts from a post ID?
- Quering array of post types & pagination. Articles are repeating sometimes on different pages
- WordPress CPT archive page display sticky post first and then display the rest of the posts in same Query
- Remove date rewrite rule for custom post type archive page
- Why using archive pages at all?