I thought WordPress was supposed to do all the heavy lifting as far
as filtering by categories, tags, authors, etc.
It does. Which is why you shouldn’t have done this:
$category = get_category( get_query_var( 'cat' ) );
$cat_id = $category->cat_ID;
$loop = new WP_Query( array( 'cat' => $cat_id ) );
In the main template files you shouldn’t be doing your own queries. Use the main loop:
<?php if ( have_posts() ) : ?>
<?php while ( have_posts() ) : the_post(); ?>
<!-- etc. -->
<?php endwhile; ?>
<?Php endif; ?>
The purpose if archive.php is to allow you to have a different template for archives. Not to manually query different posts. The only difference should be the HTML markup around the content.
Related Posts:
- Filtering a custom post type by custom taxonomy in archive template
- Why are posts from custom post type not displayed in “category” archive?
- Displaying category archive of custom post types
- Custom Post Type Archive Page: Set Posts Per Page, Paginate
- Archive page…limiting posts per page
- how do I group content in magazine-style ‘issues’?
- Regex problem in an add_rewrite_rule
- How to show related posts by category or custom post type?
- Query Custom Post by Category
- get_categories for custom post type and filter by custom taxonomy (brand) and list child categories of a defined category
- Category page only displaying the posts from a custom type
- How to list custom post types?
- custom taxonomy archive by year
- CPT Archive with core Category
- Custom Post Type Archive Page Filtering
- Show a Category X’s custom post type on Category X archive page?
- Custom post type, organized by categories
- WP Query with categories only shows one post and ignores the category
- The loop seems stuck to a single (now deleted) post
- Custom Post Type Category Link
- Custom Post type category pages template and loop
- Tag page only display 10 posts
- Archieve.php not loading for custom post type
- multiple custom post type on category page
- get_terms() parent, child and grandchild
- Use post in multiple places on a page with multiple posts
- 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
- Menu’s breaking, now showing all page links on site
- CPT archive page – show one post from each taxonomy term
- Advanced archive url structure (category, tag and date)
- How can I increase the post count for custom post types only?
- Show the categories the current post has
- Display all Categories except ones with a specific parent
- Pagination for a cpt filtered with a category
- Adding Custom Post Types to category/tag/author archives breaks header content
- Custom category taxonomy – archive page not showing up
- Excluding category from loop not working
- Custom post types not displaying per category
- Only show current category post
- How can I generate a list of post-type specific categories?
- Custom Post Type + Category archive
- Custom Post type archives / categories give 404
- How to query all custom posts of a certain type and checking what category they have
- archive.php can’t find categorized posts
- How can I set up the URL for a category archive for a custom post type?
- Categories in custom post types
- Categories and page filtering with pre_get_posts
- Stop header code from showing in category page?
- display all posts in current category
- Separate archive template to show posts and CPT by same category/taxonomy
- author archives, showing all custom post types, problem on pagination
- WordPress Custom Post Type Archive, filter by category and get pagination working
- URL of a custom post type’s post format archive?
- Display posts from Custom Post Type in category page on front-end
- Filtering WP_Query
- How do i calculate the total of values of custom fields in custom post types?
- Multiple Loops On Custom Post Type Template?
- Categories sorting
- How can I make my custom posts appear in their assigned category url?
- How to call in Custom Post-Type Categories?
- Allow user to set custom order to a list of custom taxonomies?
- get_category_parents for custom post type taxonomy
- Custom loop with multiple taxonomy queries
- Custom Post Type with archive page but no detail page
- I would like to have different styles for my posts based on the content of each post
- Separate custom categories from default category
- Checking if Post Title is Unique as Loop Criteria
- Custom post type not displaying content from single-{custom post type} page
- Create template for taxonomy results limited by Custom Post Type
- forming WP_Query for posts of all post types but from specific categories
- wp_list_categories() – current-cat class also inside posts?
- Showing posts from different categories and from custom post type
- Custom post type getting wrong categories and tags
- Custom post type multiple loop by taxonomy term
- Categories of custom taxonomy don’t show any posts
- How to display custom taxonomies with links in filter menu?
- List custom taxonomy specific to one custom post type
- Paging doesn’t work?
- Custom post type – get_day_link()
- Sort by alphabetical order archive.php page
- What is the recommended / best way to do this: Event calendar post/type in a block-based theme?
- Change CPT archive title
- Custom Tag Description unable to display just below and outside of the Loop
- PHP variable not regenerating when publishing multiple posts at the same time
- Display all taxonomy terms, add class if term applies to current post
- Multiple level category drop-down from the WordPress dashboard
- Return the latest post from a custom Taxonomy and Post Type
- Cannot add category or custom taxonomy from admin. WordPress site is hosted in Windows 16 server via IIS. No XAMPP or WAMP
- Add custom post type settings to wordress default posts
- Displaying CPT and custom taxonomy side by side in Bootstrap 4 component
- Hide parent categories when clicked, and show it’s childs
- Limit amount of posts made within a custom taxonomy
- Problem with displaying posts in the CPT category
- How to get post type and month/year before while loop for date.php file
- Group CPT posts by custom taxonomy
- Filter CPT posts by one or more categories
- Getting categories of posts under a custom taxonomy
- Custom Post Types with a common category for a blog listing
- Can’t remove front from permalinks for custom taxonomy category page