• Hi,

    Been using this plug-in to define primary cats for some time now. Works like a charm, thanks!

    Ran into some trouble recently trying to print the primary cat via PHP. I’ve tried the following code as suggested here to no avail:

    <?php
      $perma_cat = get_post_meta($post->ID , '_category_permalink', true);
      if ( $perma_cat != null ) {
        $cat_id = $perma_cat['category'];
        $category = get_category($cat_id);
      } else {
        $categories = get_the_category();
        $category = $categories[0];
      }
      $category_link = get_category_link($category);
      $category_name = $category->name;  
    ?>                                   
    <a href="<?php echo $category_link ?>"><?php echo $category_name ?></a>

    All of my posts are in many categories and the above simply prints the first category alphabetically (e.g. “Articles”).

    Wondering if anyone has suggestions to adjust the code and get it working. A solution for this is well-documented for Yoast’s version of this but, unfortunately, it would be too difficult to go back and switch now.

    Otherwise, great plug-in. Thanks, in advance, for any help you can provide.

    The page I need help with: [log in to see the link]

  • The topic ‘PHP to get Permalink Category Name’ is closed to new replies.