How to display custom post category on results

Home Forums Product Support Forums Ajax Search Pro for WordPress Support How to display custom post category on results

This topic contains 3 replies, has 2 voices, and was last updated by

 
Keymaster
5 years, 3 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #10538

    Participant

    Hi, I have a few custom posts and would like to display the custom categories for those posts in the results. I found this code but doesnt seem to be working for me (see below)

    The name of the category is ‘venues-category’.

    Also in the Advanced Title Field what would I need to type to show the category? {venues-category} ?

    add_filter( ‘asp_pagepost_results’, ‘asp_add_category_titles’, 1, 1 );

    function asp_add_category_titles( $pageposts ) {
    foreach ($pageposts as $k=>$v) {

    // Get the post categories
    $post_categories = wp_get_post_categories( $pageposts[$k]->id );
    $cats = “”;

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

    // Modify the post title
    $pageposts[$k]->title .= ” “.$cats;
    }

    return $pageposts;
    }

    #10543

    Hi,

    Yeah, that code will only work with posts and categories, try this one instead:

    Best,
    Ernest Marcinko

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


    #10544

    Participant

    Thank you Ernest. What do I need to type to display it in the Advanced Title Field section? e.g. {Venues-category} ?

    #10545

    Hi,

    You don’t have to type there anything, this is a post processing function, it’s executed after the advanced fields are processed.

    Best,
    Ernest Marcinko

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


Viewing 4 posts - 1 through 4 (of 4 total)

The topic ‘How to display custom post category on results’ is closed to new replies.