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?
- Permalink Structure for Multiple Post Type Archives by Taxonomy
- Meta_Query as a way how to setup CPT permalinks – is it a good thing?
- $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?
- Custom Post Type Archive Page: Set Posts Per Page, Paginate
- How to show more posts on an archive page?
- Querying custom posts and regular posts
- Custom Post Type Archive URL takes over page URL
- Display all custom post types in archives.php
- How to Add Pages Under Custom Post Type URL Structure?
- Using Offset in Custom Post Type Query
- Custom Post Type Archives by Date (stored as meta value) WP3.1
- Using Query Posts With Multiple Post Types And A Taxonomy
- Removing CPT slug from URL results in 404 error for archive page
- Multiple post types in archives (filter?)
- Query posts by custom post type and custom taxonomy
- How to let custom post type posts show in standard post archive (like in homepage)?
- where can I see my custom post type archive template?
- Query not returning CPT posts
- Post Rank on Single Post page based on custom field
- Custom post type archive sorted and grouped by date in post meta field
- Unable to display multiple post types in same query (WPML WP_Query)
- How to get current post id of a custom post type in a loop using template singel-{custom type}.php?
- Quickest way to get last or oldest post date – WP Query
- ‘category__and’ for custom taxonomy?
- Post the content of a specific “Custom Post Type” post within a post using a shortcode
- Separate Posts and Custom Post Type in Custom Taxonomy archive template
- Custom-post-type-archive: posts sorted/filtered by year?
- query_posts with a custom post type, a meta_query and sorting by post date?
- 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
- Setting posts per page in query_posts
- How to insert content from another Custom Post type into Post?
- Custom post types archive redirect
- just can’t get date-based archives per post-type to work
- How to query custom post types posts filtered by multiple custom taxonomies through a form selection
- Root slug of taxonomy returning 404
- Display only one post each WEEK
- Get posts between custom dates
- How to get post type and month/year before while loop for date.php file
- Custom archive page for CPT UI
- How to display custom post in archive section of the wordpress page?
- Limit the post for differents custom post type in the same wp_query
- Custom post type posts don’t show in archive widget
- 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?
- Display custom posts randomly in custom taxonomy archive
- 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
- Loop through posts of only 2 statuses
- 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
- HM CMB: Post Select Field for CPT ID
- pre_get_posts works in post type archive but not in single post
- 4 posts per page from single category
- Display Posts Query with IF function
- 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
- 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
- Custom post type pagination problem – page 1 and 2 show same content
- 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
- Custom post types not using archive structure
- How to grab data (titles, thumbnails and custom fields) from multiple posts to populate a new array efficiently?
- Pagination not working for archive
- 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