Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [get-the-category]

get_the_category ( int $id = false ) retrieves post categories. It can be used outside The Loop by passing a post id as the parameter.

0
votes
2answers
2k views

How to fetch the highest category in the hierachry for a specific post?

I understand Wordpress concept "primary category", but I do not understand how to fetch the name of the highest category in the hierarchy for a specific post? Having this code: $category_obj = ...
0
votes
2answers
821 views

Show single Child Category on Custom Post

Am hoping someone can help me pull out a single custom category name and show it on my custom post page. I've created a new custom post type 'Itinerary' as well as some new custom categories (terms): ...
2
votes
1answer
191 views

Get the category is not working on url

Although this is my first post but i have been coming here for answers so I know the rule and this isn't a duplicate because i have tried whatever i could but couldn't seem to get my codes to work. ...
2
votes
1answer
601 views

How can I get archives for specific category without category_base in the url?

I'm using this code to get archives for a specific category: function extend_date_archives_add_rewrite_rules($wp_rewrite){ $rules = array(); $structures = array( $wp_rewrite->...
1
vote
1answer
585 views

get_template_part based upon post's category

I have a WordPress website setup with 5 main parent categories each with dozens of child categories For each WordPress post in single.php, I'd like to load some content based upon each child category ...
1
vote
1answer
432 views

How to display related posts from parent category

I am using the following code to display the related posts but it is showing posts for that category only like brand showing brand posts only. What I am looking for is if I select any of the posts ...
0
votes
1answer
27 views

Style post archive blog preview based on category

0 down vote favorite I have a page showing your typical series of small post teasers - images, excerpt etc which advertise properties for lease. I would like to have the ability to add a 'new' or '...
0
votes
1answer
30 views

I can not call the categories of custom post type

This is my code that I used in the functions.php add_action( 'init', 'register_cpt_video' ); function register_cpt_video() { $labels = array( 'name' => __( 'Videos'...
0
votes
1answer
137 views

Adding custom post type to count in category

I'm working on building a section for related posts in my theme's single.php file and I'm querying things based on the count returned from count (returned from get_the_category($post->ID);) The ...
0
votes
1answer
63 views

Calling Category name without the link

I have looked to see if there is a simple function that only returns the name of a category on a post. I am looking to output it as a subheading for a list of posts but do not want it as a link and ...
0
votes
1answer
28 views

Why does the first category returned get echoed twice?

I have a category called menu items (category id 19) and two child categories Tacos and Burgers. Why does Tacos get echoed out twice? I get Tacos Tacos Burgers. while (have_posts()) : the_post(); ...
0
votes
1answer
513 views

Category ID returns as '0'?

I'm trying to populate the category id from the category name within the loop. <?php $cat_name = get_theme_mod( 'cat_1' ); ?> <?php $category_id = get_cat_ID($cat_name); ?> &...
0
votes
1answer
488 views

the_category if/else statement

I need to do the following: The sense if I have a class dportfolio - show a category dportfolio. Otherwise show usual category. I use: if ( class_exists( 'DPortfolio' ) ) { echo DPortfolio::...
0
votes
1answer
164 views

Show post if in category

I've searched a lot for options like has_category, in_category, get_the_category, but I couldn't make them work Here's my pastebin http://pastebin.com/Zi7auvtv I want this code to run only if the ...
0
votes
1answer
471 views

How to get tags and categories?

I used the following code to get tags from the post and then simply echo them: $posttags = get_the_tags($post->ID); if ($posttags) { foreach($posttags as $tag) { echo $tag->name . ', ';} ...
-1
votes
1answer
17 views

Print the associated categories of the current post starting with parent (with option to remove href)

Not sure why this seemingly elementary function is so difficult to perform, but I've spent a lot of time scouring the web, incorporating the suggestions and not getting the intended output. On the ...
-1
votes
1answer
34 views

Why does my Wordpress index has a category?

So my homepage is set to display the latest articles of my wordpress site. I use php to detect if the page has a special category in the header of my template and it works on every other pages at the ...
-1
votes
1answer
2k views

Link Back to Parent Category - Woocommerce

I´m using woocommerce and a custom post type=product and taxonomy=product_cat. I need a link back to parent category on every single product and category pages. Already read several posts in the web ...
-1
votes
1answer
514 views

Print child category slug nicename

I want to print (display) the child category slug, so I can use it in a dynamic url, on categories pages. So If I am on the category www.example.com/category/main-category/child-category Example: ...
-1
votes
1answer
61 views

How to display my categories in a list (to a post, not the sidebar)?

i want to display my categories to a post like a list. i have this (parent- and child-) categories: - Sports - Football - Basketball - Toys - Dolls - Lego - Books for example one ...
1
vote
0answers
23 views

Publish Categories for a particular Author on a given Post

Suppose I have this HTML → <div class="author-category"> <ul> <li><a href="">CATEGORY 1</a></li> <li><a href="">CATEGORY 2&...
1
vote
0answers
329 views

List only child categories within posts

I am using the_category() to display categories in my posts that are also filed in child-categories. Unfortunately this also displays the parent category which i would love to hide. Is there a way to ...
0
votes
0answers
14 views

How to set sidebar that is already in category for single page

Experts, I'm a little newbie in the programming area, so I'm having some problems with Wordpress. It's the following, I'm using a layout in which each category has its sidebar, using a plugin to ...
0
votes
0answers
8 views

How to display the name of categories when multiple filtered?

In WordPress, if I hit https://example.com/category/Pop I will get the category page named "Pop". The h1 title will also display "Pop". But what about when I use multiple category filter in the ...
0
votes
0answers
17 views

Find and Replace Words in Post Content For Specific category

I have tried my best it is still giving me blank page. My goal is to Find and Replace words in post content article for one or two specific category, Not the entire site. function ...
0
votes
0answers
558 views

Help with Wp + Mixitup code

I'm using MixItUp and having this issue. I'm calling the filters like this: <?php $categories= get_categories('child_of=14&hide_empty=0'); foreach ($categories as $category) echo '<li ...