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.

Filter by
Sorted by
Tagged with
0
votes
1answer
729 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
75 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 ...
0
votes
1answer
9k 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
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
5k views

How to sort category by custom field value

I am using the following : $catargs = array( 'meta_key'=> 'category_custom_order', 'orderby' => 'meta_value_num', 'order'=> 'ASC', ); but I can get the ...
0
votes
1answer
620 views

Get all categories post is not in

I am trying to get a list of all categories that the current post is not in. I made it this far... $categories = get_the_category( $post_id ); $nocats = get_terms('category', array('exclude' => $...
0
votes
2answers
316 views

Output the text before category

I need to output the text before the_category. In result, it should be something like Posted on September 20, 2014 IN MyCategory Here I use the_time('F j, Y') and start from here I use ...
0
votes
2answers
7k views

How to exclude specific category from the get_the_category(); array

In my loop I've added: <?php $categories = get_the_category(); $separator = ' '; $output = ''; if($categories){ foreach($categories as $category) { $output .= '<span class="post-...
0
votes
3answers
5k views

get_the_categories() but exclude children of “Uncategorized”

In this function, I need to exclude any categories from $categories which are children of "Uncategorized". function get_cats(){ $post_cats= array(); $categories = get_the_category(); ...
0
votes
1answer
55 views

I want to know how to output child categories related to parent categories

You are currently adding two parent categories: Events and Magazine. The magazine has child categories associated with interviews and reviews. Below is a hierarchical representation of the current ...
0
votes
1answer
18 views

Why get_category() function is not working not working when embedded in a page?

I'm using PHP everywhere plugin to insert PHP snippets in my page. Specifically, I'm trying to get posts count in a category. Here's my code: <?php $count=get_category(607)->count; echo $...
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
201 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
291 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 ...
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 ...
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 ...
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
776 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
185 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' ...
0
votes
1answer
1k 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 ...
0
votes
2answers
205 views

Unable to differentiate between two categories under custom post type on single.php

I have created A custom post type as mentioned in my older question When I try to use get_the_category() function to retrieve the category of the post(if it is symphony or noir). It returns "Array". ...
0
votes
1answer
2k views

the_category() tag not styling HTML or CSS

I am having problems getting my the_category() template tag to style accordingly with the rest of my theme. I believe this is because the HTML isn't output the same way as the the_author() and ...
0
votes
1answer
952 views

Anchor tag generates blank href attribute using echo esc_url( )

Following is my categories page. It's listing the all categories in the page. But when <a href> gets blank value here. see the attached screen shot. Why href is blank here li><a href="&...
0
votes
1answer
859 views

Exclude category from get_the_category

I want to exclude a specific category from the loop, here's what I tried: Original code: // auto posts by cat if( $bawmrp_options['auto_posts'] == 'cat' || $bawmrp_options['auto_posts'] == '...
0
votes
1answer
305 views

Can't get Category link inside get_posts

I created a simple function to display the latest posts. Inside the function there is a conditional to display the post category. I found that to display the category name, using $category = ...
0
votes
1answer
301 views

Category Page Template - Can't get category ID

I am creating a category template that uses WP_query to get posts from my custom post type... <?php $query = new WP_Query( array( 'post_type' => array( 'mycpt' ), 'posts_per_page' => 5 ) ); ...
0
votes
1answer
1k views

How to Highlight current category on category and single page template?

On Wp Forums, I found a code that shows categories with images and it works very well. But I couldn't figure out how to highlight current category on category.php and single.php Here is the code that ...
0
votes
1answer
3k views

Get posts from a top category and group by child categories

I have a CPT Called "Membres" (members in English). So after that I created a category called "Membres" and his child categories. Parent category "Membres" - Subcategory1 (3 post inside) - ...
0
votes
1answer
6k views

How to get parent category ID in single page template

How can I get parent category ID in single page template, outside of loop? $category = get_the_category(); echo $category[0]->term_id; The code isn't working outside loop correctly.
0
votes
1answer
529 views

Get only X number of categories

How can i get only x number of categories using the_category. I triesd a few thing but none worked. I dont want to use get_the_category
0
votes
1answer
1k views

Finding and removing duplicates within WP Arrays

I'm looking to see if it's possible to find and remove duplicates from the arrays generated below. I've tried array_unique array_merge and they haven't worked. $category = get_the_category(); $tags =...
0
votes
1answer
7k views

Get 1st parent category id from post

I have this structure for my categories: Issue 4 - News - Supporting our troops - Breaking news <?php $category = get_the_category(); $parent = $category[0]->...
0
votes
1answer
816 views

How to correctly display category's slug as a class?

I want to display category's slug as a class. I try to code and put this into functions.php add_filter('the_category', 'my_custom_get_the_category_list'); function my_custom__get_the_category_list($...
0
votes
1answer
902 views

Compare current post Category in select menu

I have done this many times but not via a form so i am getting a weird issues when trying to assign a "selected" based on the current post term id... Maybe the use of _the_category and then ...
0
votes
1answer
2k views

Outside the loop Category name with link

I want to display the category Name by using category ID with link to category page (out side the loop). here is my code... <a href="<?php get_category_link('23'); ?>"><?php echo ...
0
votes
2answers
461 views

loop inside a loop : search for posts in the same category

Could someone tell me how i could make this work? i have a loop, and i would like to create another loop to find the other posts from the same category : but this does not work : <?php while ( ...
0
votes
1answer
358 views

Subcategory is displayed before Parent Category

I'm current using the following code to echo the categories of my post : <?php foreach((get_the_category()) as $category) { echo $category->cat_name . ' '; } ?> So, for example, I have ...
0
votes
2answers
1k views

Can't Get Parent and Child Categories of Custom Taxonomy to Display

I have a Custom Post Type set up with a Custom Taxonomy. For this Custom Taxonomy, I'm trying to figure out how to echo out the titles of the parent category and current child category within it. ...
0
votes
1answer
366 views

Better way to exclude category output for post/pages?

I always assumed there was a way to exclude certain categories from being output in the loop using get_the_category, the_category, or one of the term related functions. After looking around it seems ...
0
votes
1answer
22 views

I can get posts in all categories. But I want to get the custom post type I created

i created custom post type ('Ürünler') with some plugin. And I want to pull all posts from here with category titles. My code doesn't see the custom post type. I'll be happy if you can help me. $...
0
votes
1answer
41 views

Show subcategory name selected in specific category woocoommerce

Hi basically I have categori ID number (134) that has 2 child of that (red and blue). I selected the blue one. I want to display only the selected one (blue). But at the moment the show all ...
0
votes
0answers
15 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
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 ...
0
votes
1answer
32 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 ...
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
273 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
1answer
142 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 ...