Title: mccreath's Replies | WordPress.org

---

# mccreath

  [  ](https://wordpress.org/support/users/mccreath/)

 *   [Profile](https://wordpress.org/support/users/mccreath/)
 *   [Topics Started](https://wordpress.org/support/users/mccreath/topics/)
 *   [Replies Created](https://wordpress.org/support/users/mccreath/replies/)
 *   [Reviews Written](https://wordpress.org/support/users/mccreath/reviews/)
 *   [Topics Replied To](https://wordpress.org/support/users/mccreath/replied-to/)
 *   [Engagements](https://wordpress.org/support/users/mccreath/engagements/)
 *   [Favorites](https://wordpress.org/support/users/mccreath/favorites/)

 Search replies:

## Forum Replies Created

Viewing 5 replies - 1 through 5 (of 5 total)

 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[WP Popular Posts] Add post date to the post_html attribute](https://wordpress.org/support/topic/add-post-date-to-the-post_html-attribute/)
 *  [mccreath](https://wordpress.org/support/users/mccreath/)
 * (@mccreath)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/add-post-date-to-the-post_html-attribute/#post-4546177)
 * I’m also interested in being able to do this.
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[WP Popular Posts] Request: Add {date} as option for custom HTML](https://wordpress.org/support/topic/request-add-date-as-option-for-custom-html/)
 *  [mccreath](https://wordpress.org/support/users/mccreath/)
 * (@mccreath)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/request-add-date-as-option-for-custom-html/#post-4391983)
 * +1
 * This is the only thing that this plug-in doesn’t do that we really need.
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[WP Category Permalink] Retrieve permalink category in loop](https://wordpress.org/support/topic/retrieve-permalink-category-in-loop/)
 *  Thread Starter [mccreath](https://wordpress.org/support/users/mccreath/)
 * (@mccreath)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/retrieve-permalink-category-in-loop/#post-4516722)
 * oops! double-post.
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[WP Category Permalink] Retrieve permalink category in loop](https://wordpress.org/support/topic/retrieve-permalink-category-in-loop/)
 *  Thread Starter [mccreath](https://wordpress.org/support/users/mccreath/)
 * (@mccreath)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/retrieve-permalink-category-in-loop/#post-4516721)
 * It would be a nice-to-have. I figured it out once I took the time to read through
   your PHP. The requirement for the particular site that I’m working on is that
   one, and only one, category be displayed with each post on the home page and 
   archive pages. Most posts will only be in one category, but a certain number 
   will be in two and I wanted to have control over which one displayed.
 * Here’s what I ended up writing for my page:
 *     ```
       $cat_id = get_post_meta( $post->ID , '_category_permalink', true );
       if ( $cat_id != null ) {
           $cat = get_category( $cat_id );
           $category_link = get_category_link( $cat_id );
           $category_name = $cat->name;
       } else {
           $cat = get_the_category();
           $category_link = get_category_link( $category->term_id );
           $category_name = $cat[0]->cat_name;
       }
       echo '<a href="'.$category_link.'">'.$category_name.'</a>';
       ```
   
 * I also changed the action word to “Primary” instead of “Permalink” because that
   makes more sense for the usage that we have.
 *   Forum: [Plugins](https://wordpress.org/support/forum/plugins-and-hacks/)
    In
   reply to: [[WP Category Permalink] Retrieve permalink category in loop](https://wordpress.org/support/topic/retrieve-permalink-category-in-loop/)
 *  Thread Starter [mccreath](https://wordpress.org/support/users/mccreath/)
 * (@mccreath)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/retrieve-permalink-category-in-loop/#post-4516715)
 * Ah, figured it out. I didn’t realize the plug-in was creating a post_meta field.
   All good!

Viewing 5 replies - 1 through 5 (of 5 total)