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
- get term archive url / link
- How to get the custom post type from an archive page?
- How to show Y number of custom posts after every X normal posts?
- Hide/Show only specific categories in wp-admin new-post.php
- Custom Post Type Archives with 0 Posts Redirects as 404
- Archive page with multiple taxonomies rewrite
- Date archives for custom post type
- Custom Post Type, Two categories, Two columns with Pagination
- New WP_query in template not working with CPT+category on some pages
- Display types of posts in edit.php instead of All, Published, Scheduled and Draft
- Display custom field of specific post where post title matches variable
- Group posts by custom post type
- Changing number of posts per page on CPT-archive.php, have tried 20-30 code chunks so far
- Displaying CPT and custom taxonomy side by side in Bootstrap 4 component
- Can’t remove front from permalinks for custom taxonomy category page
- Store CPT ‘Reviews’ average ratings to a WordPress DB table or to a DB custom table?
- Display Custom Taxonomy Alphabetically
- Pre-selecting the category for a custom post type
- Use “archive” as slug for custom post type
- Display related custom taxonomy posts in sidebar
- Conditional for a Single Post That Belongs to a Category?
- Using wp_query to modify the loop in index.php for a CPT
- looping though custom post types and only return results in a given taxonomy
- How to conditionally add Custom Post Type to Front Page
- Unable to edit categories in custom post type
- get custom post type value in header.php [closed]
- Custom Post Type setup
- Need to have an archive widget which organizes and displays a custom post type using a custom date field
- Problem with multiple loops in wordpress theme
- Retrieve Custom Taxonomies with Description and Slug
- How can i loop through custom post type according to custom meta field?
- Changing WordPress sort order for returned child pages
- Multiple custom post type queries causing wrong post types to be grabbed in taxonomy + single templates?
- Filtering posts based on three taxonomies
- How to set “section categories”?
- Add extra elements to the_post in a custom post_type
- Wanting to list all Post types under a common category
- How to show posts of the same category on a page?
- Order archive custom posts by taxonomy term [duplicate]
- How to prevent post to repeat on my loop?
- Dropdown switching subcategories portfolio
- Load different template for CPT (in loop) in my plugin?
- How to loop custom post type posts by author?
- Category / Custom Post Type permalink issue
- Loop through multiple custom taxonomy terms and display posts for a custom post type
- is_singular won’t call my functions?
- loop through custom post-type with two meta_keys
- Remove plugin’s custom post type archive page and single pages [closed]
- How to exclude certain portfolios from a loop
- Group search results by post type, but having a unique heading for each section?