get_query_var
will get the category from the main query, and it is only going to be set for some pages, such as category archives. It is not set for “single” pages or tag archives or a many other kids of “pages”.
The value that get_query_var
returns is something like a ‘search’ variable. It will be set when the query is instructed to look for posts in a particular category. It doesn’t reflect the value of current post in the Loop, though of course if get_query_var('cat')
is set then all posts should be assigned to that category.
What you want to get the category for the current post in the Loop is get_the_category
, but it should come after the_post
. get_the_tags
will do the same for tags and the more generic get_the_terms
can be used for any taxonomy.
Related Posts:
- Category archive page – loop through posts of certain tag (with pagination) – pre_get_posts
- Echo text using is_tag
- Conditional category & tag statement
- Editing Loop So It Targets Specific Tags?
- Display all categories but only if they have posts in them that have a specific tag assigned
- How to add an empty entry to masonry?
- Loops in category description
- Is There a Difference Between Taxonomies and Categories?
- What is the difference between a “tag” and a “category”?
- How to check if I’m on the last page of posts?
- get all tags from category
- 404 Error On Category and Tags Pages
- Checklist of selected categories
- Default WP Gallery – show only galleries of a certain category
- How to tax query X number of posts related by tag first, then by category if not enough in tag-related
- Category and tag with same name
- Loop with Dynamic Categories
- In the tag archive – display count of posts for each category they belong to
- Automated adding of one tag to all the posts in a category
- How can I create a loop to build slides based on multiple categories using Coda Slider
- Categories list loop – add separator every year
- How would you create a “weekly” archive?
- Exclude most recent posts from specific category in wp_query()
- How to exclude categories from recent posts, recent comments & category widgets?
- Listing all posts from current category on page
- Deleting All tags except categories Wp database
- Get tags specific category
- Listing Parent, Child and GrandChild Categories and then the PostTitles on Page Template !
- Category vs Tag vs Table
- Help with multiple dropdown tags search
- Custom WP_Query for current category (in category.php)?
- Retrieve all posts within tag OR category?
- How to find the number of Tags a post has?
- How to not treat categories as tags in feeds
- How to customize tag and category post listings to show introductory content?
- How get permalink for the current category or tag?
- Display tags from specific category in select fields
- Offline WordPress Application
- Find out which user created a category or tag?
- How to make 2 tag feeds show up on 1 page?
- Class active for Archive link – looped out
- Taxonomy name repeating when showing 2 posts from each category
- Different templates for different category tags
- Site search needs to find posts for category topic AND Tag or keyword thats not in the post
- Display the last post by each category?
- Get link which associated with a specific category and tag
- Counter in loop in foreach
- How to exclude the last post from a category(featured for example) from the main loop?
- menu using category and tags
- Order by category titles
- ajax for filtering posts by category in wordpress loops
- Limit get_categories to show each category once
- new WP_Query all post in a category inside the loop
- Problem with different query loops (and “main loop”) on category template page!
- How to add orderby parameter for sorting on category.php
- How to loop custom post_type from (a) specific category(ies)?
- Display all product tags associated with a specific product category
- Category tags with comma’s
- Display posts of certain categories to specific user roles
- Tags Instead of Category
- Category nicename inside loop in wordpress
- filter a loop base on specific category
- Problem with multiple loops in wordpress theme
- Filter categories/tags to display in multiple metaboxes for selection in back-end
- Pretty URLs with Categories and Tags
- Autolinking keywords in text with tags
- Maintaining a separate posts page for certain categories and don’t show those on home page
- Are tags different than categories?
- How to get posts using category slug in ClassiPress?
- Posts made to category don’t show up (do show up on frontpage)
- Show Posts via cat+cat in URL that are in both Categories doesn’t work
- Help to display the current categories and tags of a post
- Hide specific category tag on single post page
- Filtering posts in category by tag URL
- Regarding Tags And Categories
- How to show entries related to main category
- Please tell how to stop the category from showing up on posts
- Sidebar by Category Conditional Statement not functioning
- Loop by category and meta_key
- Re-coding category-template.php to go to custom URL
- Assign a class to first element in category in loop
- Tag Menu items based on their categories
- Hide category name using mod_rewrite
- Category page shows only 1 post when that post has more than 1 category?
- Configure query with multiple categories in a custom order?
- How to exclude category and post_tag taxonomy while displaying custom taxonomy?
- How can I modify this code to iterate over an array of categories?
- How to exclude a specific categogy from a custom page template
- How can I hide the category term for posts with none set?
- htaccess redirect for all categories converted to tags now showing 404
- altering theme – content generated by PAGES not PORTFOLIO
- My Query is getting the wrong data
- Search tag within category
- How do i add custom post types to this query?
- Custom WordPress category page showing all posts rather than the specified category
- How to show only specific tag in wordpress loop
- Do not show all post from all categories, just show posts from category in current loop
- Can’t seem to get an else statement correct? [closed]
- Echo Category In Loop
- Weird html output of single_cat_title – is not inside of the html element?