get_the_category() for private page
-
-
Yves Saint-LaryMember# 3 years, 5 months ago
Hi,
Can you help me use the function get_the_category() for private pages?
I want to display the category name for instance :
$categories = get_the_category();
$category_name = $categories[0]->name;
echo $category_name;Thank you
Yves
-
ThomasKeymaster# 3 years, 5 months ago
Hi,
Yes, this is on our todo list, not sure why we missed to add the categories :p
For now, this should work (not tested):
$terms = get_the_terms( get_the_ID(), 'cuar_private_page_category' ); echo implode($terms, ', ');
However, I’m just using the standard get_the_terms function with our taxonomy named ‘cuar_private_page_category’.
Regards.
Want to help WP Customer Area? It only takes few seconds!
Rate & review the plugin on WordPress.org 🙂 -
ThomasKeymaster# 3 years, 5 months ago
Reason: get_the_category is made for ‘posts’ from WP only, no for custom taxonomies, you need to use get_the_terms instead of get_the_category.
Want to help WP Customer Area? It only takes few seconds!
Rate & review the plugin on WordPress.org 🙂 -
Yves Saint-LaryMember# 3 years, 5 months ago
Hi Thomas,
Ok great, that works fine!
I got an error on: echo implode($terms, ‘, ‘);
I changed it for this: $term_name = $terms[0]->name; echo $term_name;
Thank you so much and keep up the good work with this great plugin!
-
ThomasKeymaster# 3 years, 5 months ago
You’re welcome, and thank you for your kind words!
Want to help WP Customer Area? It only takes few seconds!
Rate & review the plugin on WordPress.org 🙂
-
The topic ‘get_the_category() for private page’ is closed to new replies.