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:
- How do I query a custom post type with a custom taxonomy?
- what is the correct way to compare dates in a WP query_posts meta_query
- Custom Post Type Archives by Year & Month?
- Get custom post type slug for an archive page
- How to get post content by calling ajax?
- How to show all posts of the category in wordpress?
- Get the ID of the latest post
- Using meta_query, how can i filter by a custom field and order by another one?
- Custom post type pagination 404 fix?
- Return all custom meta data for one custom post type
- Adding content to archive and taxonomy pages on custom post types?
- Filtering a custom post type by custom taxonomy in archive template
- Display a query with multiple post types and same relationship on a single page
- Permalink Structure for Multiple Post Type Archives by Taxonomy
- get term archive url / link
- How to get the custom post type from an archive page?
- How to remove “Archive:” label from archive title
- Fail to compare dates in meta_query
- How to filter custom posts by tags and custom fields?
- Order by & include array by specific post ids
- Why are posts from custom post type not displayed in “category” archive?
- How to call a custom post with get_posts() instead of query_posts()?
- Custom Post Type Archives by Date and Taxonomy
- Displaying category archive of custom post types
- Custom post types – Use post_id in permalink structure when using has_archive => true
- Meta_Query as a way how to setup CPT permalinks – is it a good thing?
- Custom post type archive 404’s with paginate_links
- $query->set in pre_get_posts is unintentionally affecting the backend
- Pagination throws 404 error on custom taxonomy archive pages
- Setting up custom post type archives in WP3.1? Any luck?
- Proper way of making custom post type landing page or archive page
- How do I display two separate taxonomy archives for two post types that share a single taxonomy?
- Custom Post Type Archives by Date with Custom Permalink
- Filter for “get_post_type_archive_link()”
- How to add meta box to backend menu page
- Custom Post Type Archive Page: Set Posts Per Page, Paginate
- Change title in head on Archive page
- Display Editable Text Above CPT Archive Listings
- Custom Post Type Archives with 0 Posts Redirects as 404
- How to show more posts on an archive page?
- Archive page with multiple taxonomies rewrite
- Multiple Paginations on one Page
- Create permalink structure for one taxonomy archive per custom post type
- Archive page…limiting posts per page
- WP 3.1 – archive pages for custom content types possible now without a plugin?
- Page is defaulting to archive page and not designated template
- Display Custom Post Type Fields
- Querying custom posts and regular posts
- Date archives for custom post type
- Loading Custom Post Type Events into jQuery-based FullCalendar?
- Custom Post Type Archive URL takes over page URL
- Return only custom post types for the page, not all
- Advanced Custom Fields: query posts filtered by multiple field values
- How can I set up the URL for a category archive for a custom post type?
- ‘Blog Archive’ suddenly appeared on custom post type; how to remove
- Categories in custom post types
- Is it possible to remove the word “date” from archives?
- WP Build-In Post selector for CPT
- Display results from two Custom Post Types in page template
- Taxonomy Query of Custom Post Displays Archive Instead of Posts
- Generate daily archive whenever any post type is added
- 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?
- How to apply order on custom taxonomy and custom meta key on custom post type
- Stop header code from showing in category page?
- is_singular won’t call my functions?
- Query Custom Post Type and sort by year
- send user to first page of results when reposting to page?
- Custom post types not using archive structure
- How to turn custom-post archive into an overview page, listing the metadata of the posts?
- How to grab data (titles, thumbnails and custom fields) from multiple posts to populate a new array efficiently?
- Query custom type posts by array of IDs
- Pagination not working for archive
- how to pass args for archive.php query?
- How to have a dynamic slug and rendering the archive-{post_type}.php?
- Remove plugin’s custom post type archive page and single pages [closed]
- Inserting two categories
- How do I correctly query posts from a post ID?
- How to exclude certain portfolios from a loop
- Render a loop in Timber (twig for WordPress)
- show custom post’s post in two different divs [duplicate]
- How to get Custom post type by related category ID
- Trying to set up a range filter for related custom post types
- Quering array of post types & pagination. Articles are repeating sometimes on different pages
- Display ACF object field data using Elementor Custom Query
- Assign a tag to custom post type using a query
- WP Query + custom fields: How to query event posts from the current date backwards 6 months and organize it month by month?
- Show custom category archive as front page and remove taxonomy slug from urls
- WordPress CPT archive page display sticky post first and then display the rest of the posts in same Query
- Custom Post Type posts not getting picked up in archive widgets
- Remove date rewrite rule for custom post type archive page
- Why using archive pages at all?
- Taxonomy term archive claims there are no posts, but there are. How to resolve?
- A theme has 3 default types posts, services and portfolio in its posts grid.I want to add my custom post type products How can I achieve that?
- Separate archive template to show posts and CPT by same category/taxonomy
- Create an archive page by combining two post type
- author archives, showing all custom post types, problem on pagination
- How do I get an intermediary page between 2 custom post types?
- WordPress Custom Post Type Archive, filter by category and get pagination working
- Custom Taxonomy archive with url parameters