get_the_category() for private page

    • # il y a 3 années et 5 mois

      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

       

    • Thomas
      Maître des clés
      # il y a 3 années et 5 mois

      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 🙂

    • Thomas
      Maître des clés
      # il y a 3 années et 5 mois

      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 🙂

    • # il y a 3 années et 5 mois

      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!

    • Thomas
      Maître des clés
      # il y a 3 années et 5 mois

      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 🙂

Vous lisez 4 fils de discussion

The topic ‘get_the_category() for private page’ is closed to new replies.