This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

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

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #10538
    mikeyandmikeyand
    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
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hi,

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

    #10544
    mikeyandmikeyand
    Participant

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

    #10545
    Ernest MarcinkoErnest Marcinko
    Keymaster

    Hi,

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

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘How to display custom post category on results’ is closed to new replies.