Reply To: How to display post's category on related posts

Home Forums Product Support Forums Related Posts Pro for WordPress Support How to display post's category on related posts Reply To: How to display post's category on related posts

#7161

Ernest Marcinko
Keymaster

Hi!

I think a better solution would be to use a filtering function, so the source code is not changed and it's update proof.

I've put together a function that might do the trick. Put this to the functions.php file in your active theme directory:

add_filter( 'rpp_item_after_postprocessing', 'rpp_add_category_titles', 1, 1 );
 
function rpp_add_category_titles( $post ) {
 
  // Get the post categories
  $post_categories = wp_get_post_categories( $post->ID );
  $cats = "";

  // Concatenate category names to the $cats variable
  foreach($post_categories as $c){
      $cat = get_category( $c );
      $cats .= " ".$cat->name;
  }                

  if ( $cats != "")
    $post->author  = $cats;
 
  return $post;
}

Make sure to save the related posts pro options to clear the posts cache.

I haven't tried this code, but I'm hoping it will work.

Best,
Ernest Marcinko

If you like my products, don't forget to rate them on codecanyon :)