Support » Plugin: Relevanssi - A Better Search » Snippets not created from Custom Fields?

  • Hi there…first of all, LOVE this plugin, absolutely awesome to work with right out of the box.

    Everything is working great for me using some Custom Post Types and Custom Fields (which were created using Custom Field Template plugin).

    The search results are returned when there is a hit within the custom field of my post types, but the only problem is there is no snippet! Snippets work for regular posts (naturally) and for page results, but not for custom fields, I just get the infamous three dots.

    I know its finding the individual words because when I use %total%, I can see how many hits it saw. But it won’t create the snippet (Custom Snippets is turned on).

    Any idea why this could be?

Viewing 15 replies - 1 through 15 (of 36 total)
  • Here is a screenshot if need be:

    http://goodchee.com/econest-search.jpg

    Plugin Author Mikko Saari

    (@msaari)

    Relevanssi doesn’t build excerpts from custom fields. It’s not a bug.

    However, not getting an excerpt at all is a bug. When I try this at my test blog, I just get an excerpt of the post.

    What’s in your search results template? A call to the_excerpt()? I checked at your site and the Nesting Instinct entry that’s causing trouble does have the words “clay straw” in the post content, so it should definitely be highlighted…

    Well, it’s hard to say what’s the problem without taking a closer look under the hood.

    Interesting…well, here is what I have in my search template:

    [Code moderated as per the Forum Rules. Please use the pastebin]

    Also, to give you a little more information:

    One of the Custom Fields I have is called ‘Description’. If I call that into the Search Template, hoping that it would just return the highlighted portion, it returns the entire custom field, rather than a snippet.

    Just thought I’d mention that. I didn’t expect it to work, but just in case you might suggest it.

    Plugin Author Mikko Saari

    (@msaari)

    Relevanssi custom snippets work through the post excerpt. If you enable custom snippets, Relevanssi will go through the search results, create new excerpts and replace the post excerpts with the new excerpts.

    So, only way to get the custom excerpts visible is to use excerpts, either with the_excerpt() or relevanssi_the_excerpt().

    Hmm…so does this mean it should be working? Not sure if my code came through, but here is the Pastebin:

    http://pastebin.com/gcF6NWDM

    I also tried using relevanssi_the_excerpt(), no go either.

    But from what I gather from your posts, if the search result exists within a Custom Field, it will not build or display an excerpt or snippet of any kind, even if I use relevanssi_the_excerpt()?

    Plugin Author Mikko Saari

    (@msaari)

    If the search result exists only within a custom field, Relevanssi should build a default excerpt, which is taken from the beginning of the entry. At least that’s what it does on every blog I have.

    So, unfortunately I don’t have a clue what’s going on here, and just looking at the results isn’t going to help much. There’s something in your blog that’s throwing the Relevanssi excerpt creation off the tracks and figuring it out would take some closer debugging.

    Well I tried this same technique on another site and same thing occurs…I’m wondering if it possibly has to do with that I am using Custom Field Template to create my custom fields, since that’s the only plugin that these two sites have in common.

    What do you use when you create your custom fields?

    Plugin Author Mikko Saari

    (@msaari)

    I always do them manually.

    Hi guys.

    I was having the same problem, the excerpt created by relevanssi does not contain any content from custom fields. This is my workaround:

    Let’s say you are in the following situation. You have a post-type my-custom-post-type (or post or page) that is extended with custom fields (aka meta-data) myfield1 and myfield2. We want the content of those field be contained in the excerpt generated by relevanssi. Since the the_content hook is used by relevanssi to get the content it creates the excerpt from, we need to implement this hook, either in you functions.php or in you plugin file (Make sure to replace my-custom-post-type, myfield1, myfield2 and functionnames in the following code):

    [Code moderated as per the Forum Rules. Please use the pastebin]

    This is not the nicest hack but it works perfectly. I would request the following feature from the developers: Register a custom hook for this purpose so we don’t need backtracing and make the $post object available as you would expect it when the_content is triggered.

    Awesome, Davidn! Would you be able to create a pastebin so I could see the code you are using?

    Plugin Author Mikko Saari

    (@msaari)

    Ah, good idea davidn.de – I’m always in favour of creating useful filter hooks. I’ve got 2.9.1 almost complete, I’ll squeeze this in.

    Ah thank you moderator, it’s all gone. Never mind, I mist this rule (but why is there a code tag in this form???)

    Here we go: http://pastebin.com/Zx5qx4kN

    Hey David, I’m having some issues getting this filter to work correctly (I keep getting invalid arguments when it tries to implode).

    If its not too much trouble, can you show me a pastebin of what it should look like if my Post Type is “Article” and the custom field is “Article Text”?

    I so greatly appreciate this!

Viewing 15 replies - 1 through 15 (of 36 total)
  • The topic ‘Snippets not created from Custom Fields?’ is closed to new replies.