WordPress.org

Ready to get started?Download WordPress

Forums

Relevanssi - A Better Search
[resolved] Always the same post using relevanssi_excerpt_content (4 posts)

  1. schwarzgrau
    Member
    Posted 1 year ago #

    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/

  2. schwarzgrau
    Member
    Posted 1 year ago #

    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.

  3. Mikko Saari
    Member
    Plugin Author

    Posted 1 year ago #

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

  4. schwarzgrau
    Member
    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic