• Resolved schwarzgrau

    (@schwarzgrau)


    I’m trying to use the filter hook relevanssi_excerpt_content to show a custom field called description in my search-excerpts.

    add_filter('relevanssi_excerpt_content', 'fkp_search_custom_excerpt', 10, 3);
    function fkp_search_custom_excerpt($content, $post, $query) {
            $content = $post->description;
        return $content;
    }

    It seems I’m doing something completly wrong, cause on every post excerpt in the search results, I get the ‘description’ from the last post displayed.

    http://wordpress.org/extend/plugins/relevanssi/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter schwarzgrau

    (@schwarzgrau)

    What makes it even weirder is, that it not using the ‘description’ from the last post displayed, it always uses the ‘description’ from one single post (by the way the first post made in this custom post type).

    If I use var_dump($post) on my search-results everything seems fine, except of the excerpt, which is always the same.

    Plugin Author Mikko Saari

    (@msaari)

    Try relevanssi_pre_excerpt_content instead of relevanssi_excerpt_content – do you still get the same excerpt every time?

    Thread Starter schwarzgrau

    (@schwarzgrau)

    Now my function looks like this

    add_filter('relevanssi_pre_excerpt_content', 'fkp_search_custom_excerpt', 10, 3);
    
    function fkp_search_custom_excerpt($content, $post, $query) {
            $content = $post->ID . ' - ' . $post->description;
        return $content;
    }

    It’s the right ID now, but the description only shows the three dots.
    But if I change $post->description to get_field('description' $post->ID) (since I’m using Advanced custom fields) everything works like expected.
    Thank you a lot Mikko. I never saw someone here giving that great support to everyone (even to the not premium users) like you do.
    I wish I would be able to afford the premium version.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Always the same post using relevanssi_excerpt_content’ is closed to new replies.