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?
- Get the children of the parent category
- What is the difference between a “tag” and a “category”?
- How to check if I’m on the last page of posts?
- Can’t custom taxonomies have same terms (slugs) as categories?
- How to display non-hierarchical taxonomy as terms with checkboxes?
- Should category.php and The Loop be used if the query needs to be customizable?
- How do the ‘tag’ and ‘category’ (default) taxonomies do ‘save_post’ action?
- Control term order on a per-post basis
- get all tags from category
- 404 Error On Category and Tags Pages
- Exclude the category from the WordPress loop
- How do I get the category URL from get_the_category?
- Checklist of selected categories
- Rewrite URL with category and tag combined using WP_Rewrite
- get_field not displaying my custom field value
- 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
- Use tag interface for hierarchical taxonomy?
- Rearranging posts based on categories
- WP_Query not looking at child category
- Sort posts by tags in category pages
- Randomise results from a category page?
- How to search for categories and/or tags?
- Using URL parameters, list posts from category and custom taxonomy
- Display all posts in category, with specific tag posts at top
- How to get the url to tag & category base set by the user?
- Show div only if post is in specific category
- Filter categories using tags
- Sticky posts on home page, search, tag and archives without plugin
- How to show a category post to a specific registered user
- Are Categories, Tags and Custom Taxonomies any different in regards to SEO?
- Category and tag with same name
- Display list of Sub-Categories and the posts they contain, within one main Category
- Create subdomains for tags and categories
- Loop with Dynamic Categories
- In the tag archive – display count of posts for each category they belong to
- Is it possible to disable certain user roles from creating tags?
- 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
- Moving Categories submenu to Media, but still opens Posts menu
- what is the action hook code to supporting product category condition in single product page of woocommerce?
- Remove child products from woocommerce category page [closed]
- Get a list of commas separated categories inside a loop
- Categories list loop – add separator every year
- How would you create a “weekly” archive?
- Exclude most recent posts from specific category in wp_query()
- When using get_categories or similar, is it possible to filter results that contain certain Tags as well?
- How to exclude categories from recent posts, recent comments & category widgets?
- How to totally get rid of Category in my blog?
- Root level category, tag, author and archive pages to work
- Listing all posts from current category on page
- Showing all the posts in one page?
- Categories and Tags returning 404 on the sidebar when using ugly permalinks
- has_category() for parent category
- Display one latest post from multiple categories
- Conditional Tag for sub cagtegories?
- Deleting All tags except categories Wp database
- How do I get the total number of categories in a list of search results?
- Is it possible to put tags and category information in the post as text?
- Script to duplicate categories as tags
- Check if post belongs to any category
- Search by word, category, tag, author
- Remove Categories and Tags from Admin Dashboard
- How do I display the posts from a custom post type on a category.php page?
- How to group the loop posts in a particular by author?
- How to filter archives both by category and tag?
- Remove Archive Headline and Archive Intro Text fields on category and tag archive pages in WordPress Admin with Genesis framework
- display most popular tags of category?
- Get tags specific category
- Display products for a category, sorted by post_excerpt
- Can paginate_links() be customized for a specific category or tag?
- Exclude category from loop not working
- Any way to assign Post Categories and Tags to Links?
- 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)?
- Hide tag and category boxes from the post editor
- If newest post of category is newest post in general, skip first post of category
- Retrieve all posts within tag OR category?
- How to find the number of Tags a post has?
- a-z list, categories and sub categories in loop
- How to not treat categories as tags in feeds
- Categories: A Greenhorn Question on Strategy (Not Code)
- How to customize tag and category post listings to show introductory content?
- Why would in_category only return one post in a specific category?
- functions.php conditional tag – only show in single.php?
- Is it possible to select and edit the way the most recent post from a certain category is displayed on the page?
- Are Category or Tag Archive Pages Possible?
- Displaying multiple loops based off of category
- Warning: sizeof (): Parameter must be an array or an object that implements Countable, On products pages
- How to loop only categories without posts (+ show category featured image with acf) [closed]