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
0answers
11 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 ...
2
votes
1answer
26 views

How to display recent / random posts by its category

trying to display random posts from each category that my custom post belongs to (it is related to 2 categories). I am trying to get post categories by id. I have tried to put category ID manually but ...
2
votes
1answer
17 views

Marking old posts as no longer relevant

I am working for a company with several products that will merge into a single product. They want to keep their old blog posts from the last few years but have a notice at the top to warn users that ...
-2
votes
1answer
36 views

How to insert the first letter in uppercase [closed]

short question, I have a variable concatenated with a get_the_title and get_the_category, and I need the get_the_category to show the first letter in capital letters. <?php echo get_the_title().' ...
0
votes
1answer
13 views

Get only children category name

On a single post, I display the post's categories like this: $categories = get_the_category($id); My category hierarchy is: cat1 parent of cat2, parent of cat3, etc. I would like to display only ...
-1
votes
1answer
13 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 ...
0
votes
1answer
26 views

Print only parent categories of post in custom RSS feed

I'm trying to print only the parent category for each post and a permalink to that category within a custom Wordpress RSS feed. Using <?php the_category_rss(); ?> prints all categories for a ...
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 ...
2
votes
1answer
38 views

How to specify which category of the post to use in case of multiple categories

In my theme, to display the featured post I have to add an extra category "featured". Now I have articles showing featured in the url instead of the main category. Any help please? Thanls
1
vote
1answer
51 views

Is there a cleaner way to get post count for a category in category.php?

Building the category.php I'm curious to know if there is a better way to get the count of posts without wp_query? In the past I've called: single_cat_title() to render the category ...
0
votes
1answer
26 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 '...
1
vote
1answer
21 views

Why is my loop not dynamically grabbing the correct Category and displaying all categorized posts?

Objective: When a category is clicked I would like the category.php page to dynamically pull in all posts filed under that clicked category. Example: News -> (Action:Click) -> Category = News ...
0
votes
0answers
16 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 ...
-1
votes
1answer
72 views

How to display a linked category name with get_the_category

I a code snippet with this bit included... $output .= '<li><a href=" ' . get_the_permalink() .' ">' . get_the_title() .'</a> ' . get_the_category() .' '. get_the_time('d M Y') . '&...
0
votes
1answer
247 views

Get category id of next / prev post inside the_post_navigation

I would like to get_the_category inside the_post_navigation. I created a custom field on Categories to assign a hex color to each category. I would like to use this color as the next / prev link ...
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
2answers
2k views

Problem with calling custom function in a foreach loop

I have a custom function in functions.php that excludes specific category from the category list: function incomplete_cat_list() { $first_time = 1; foreach((get_the_category()) as $...
0
votes
1answer
100 views

Why is it so hard to show the URL of the current category and how to do it?

If I'm on a singular page, it is quite easy to show the current post URL outside the loop: the_permalink(); If I am on a category page it is quite simple to show the category description outside the ...
2
votes
1answer
6k views

Getting key value of WP_Term object in wordpress

How I can get from php on wordpress to a value of WP_Term object. I am using the next code to get the object: $queried_object = get_the_category( get_queried_object_id()); But this return an Array ...
0
votes
1answer
35 views

Fix Warnings that shouldn't be necessary to fix

I was trying to fix some warnings and I noticed that I get constantly PHP Notice: Undefined variable: If I use : $categories = get_the_category(get_query_var('cat')); $cat_name = $categories[0]-&...
0
votes
1answer
133 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
61 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
679 views

how to get correct category of a post in case of multiple categories?

I have a custom post type called recipes.In this I have lots of recipes as posts.All these recipes are assigned to several categories. Problem : Now Consider a post which is assigned to multiple ...
0
votes
1answer
191 views

Insert post's category name into thumbnail string

Hopefully a simple question. I've added several post thumbnail sizes to functions.php using add_image_size. They are each named exactly like a post category. I would like to find a way of making each ...
0
votes
1answer
256 views

How to get the current category with custom posts

If I go to: domain.example/category/skydancers-en-blikvangers/ I want to get all the posts in the current category for skydancers-en-blikvangers, I know I can hard code the category but this needs to ...
1
vote
1answer
560 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
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&...
2
votes
2answers
40 views

Specified number of categoy posts not showing correctly

I have a code, i used to call a particular category in my post page footer and i have specified the number of posts to display but its showing all the posts from that category. here are the codes &...
1
vote
2answers
484 views

Five posts from a category in footer

I am trying to show 5 posts from a category in my home footer. I have placed this code <?php query_posts( 'category_name=entertainment&posts_per_page=5' ); ?> right in my home.php file ...
0
votes
1answer
1k views

Display data when category is empty

I have the following code which inserts data to the bottom of a product category. It works perfectly however it only displays when a product is actually in the category, id like it to display in ...
1
vote
1answer
428 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 ...
1
vote
1answer
1k views

how to cahnge <?php the_category() ?> template?

this function produce this html <ul class="post-categories"> <li><a href="#" rel="category tag" class="text">test</a></li> <li><a href="#" rel="category ...
0
votes
1answer
1k views

Display most popular posts of category

Right now in my slider I'm showing most popular post by views. However, I want to shop most popular post by views only for a certain category? The category id I want to use is "10". How would I ...
-1
votes
1answer
33 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 ...
0
votes
1answer
23 views

How to display category name from commenter's custom post

I have this code that displays the commenter's post title. I'd like to display the post category instead. I've tried every permatation of post_title to try to display the category, but with no luck. &...
0
votes
1answer
879 views

Get current category and place it in shortcode

<?php echo do_shortcode('[x_recent_posts type="post" count="2" offset="" category="Lisbon" orientation="vertical" no_sticky="true" no_image="false" fade="false"]'); ?> This is the ...
0
votes
1answer
72 views

list categories based on updated posts [closed]

I mean to order the of categories should be based on the updated posts. The category which has most recent post should come up first and so on. Suppose, I have 50 categories and i add new post very ...
2
votes
4answers
47k views

How to get category id of current post?

I need to get the category id of the current post outside the loop. First I get the category based on the post id: global $wp_query; $postcat = get_the_category( $wp_query->post->ID ); Now how ...
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
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
1answer
8k views

Echo get_the_category() outside of loop (global?)

Trying to grab get_the_category() within the loop and post to the byline within the header. // file1.php <div> <h1><?php the_title(); ?></h2> <?php echo $...
0
votes
1answer
745 views

How to exclude a category name from showing?

So I'm trying this code: <?php global $post; $my_query = new WP_Query('showposts=8&category_name=featured'); while ($my_query->have_posts()): $my_query->the_post(); $...
0
votes
1answer
1k views

Get Attachment Category Name

How can I call the name of an attachment category? Something that would look like <?php get_attachment_category_name ?> or $attachment->category_name This would simply output the name of ...
0
votes
1answer
2k views

get parent category only

Thanks to wordpress.org, the snippet below will display a list child categories link only for each respective post if there's a child category for them. <?php foreach((get_the_category()) as $...
0
votes
1answer
640 views

Get the categorie name of Event Organiser plugin [closed]

How can I get the name of a category in a custom template of the Event Organiser Plugin. So far the only thing I can get it slug of the category by reading the following variable: echo $...
0
votes
1answer
176 views

List recent posts with link to first category

I'm looking to get a list of the recent 4 posts and with it a link the the first (and only) category that the post is in. $args = array( 'numberposts' => '4', 'offset' => '0' ...
1
vote
1answer
1k views

JSON API plugin, Get posts by category return no post

Im trying to get the posts by category. using this URL: /api/core/get_category_posts/?slug=cat2 But responding this: {"status":"ok","count":0,"pages":0,"category":{"id":3,"slug":"cat2","title":"...
0
votes
1answer
856 views

Single.php category entries not showing right colours

I am trying to implement a way of having different colours for different categories in single.php. So, I have created a colour Picker field with Advanced Custom Fields and this field shows on each ...
-1
votes
2answers
90 views

Not able to display category link and name [closed]

I bought a wordpress theme and I am not able to display the category link and name. <div class="item-info">'; if($show_aut!='0'){ $author = get_author_posts_url( get_the_author_meta( '...
1
vote
1answer
775 views

How to get custom posts sub category link

I'm trying to echo custom posts sub category link as a view more option.For the last week, i am trying to do that, but i just can't find the right way. I've tried, category links, terms, with args, id....