Exclude ACF Fields in post_excerpt
-
Hello,
Really good job for this plugin.
I would like to know if it’s possible to exclude some ACF fields in the
post_excerptoutput ?All works fine but I created an agenda with events. And Relevanssi add date from ACF fields in
post_excerptoutput
-
By default Relevanssi uses the same custom fields for indexing and excerpts. If you remove a custom field from the indexing settings, it will be removed from the excerpts as well. Perhaps you can remove the date field from being indexed?
Another option is to use the
relevanssi_excerpt_custom_field_contentfilter hook to adjust the custom field content before it’s added to the excerpts.Hello thank you very much for your answer.
If I declare custom fields with
relevanssi_excerpt_custom_field_contenthook, only these fields will be used ?I don’t have more detail about this hook in the documentation. What parameters does this hook accept?
What’s the difference with
relevanssi_excerpt_content?function custom_fields_to_excerpts($content, $post, $query) { $custom_field = get_post_meta($post->ID, 'article_technics_repeater', true); $content .= " " . $custom_field; $custom_field = get_post_meta($post->ID, 'article_wysiwyg', true); $content .= " " . $custom_field; return $content; } add_filter('relevanssi_excerpt_content', 'custom_fields_to_excerpts', 10, 3);It is possible to hide link in content. I got https://www.soundcloud.com… for example ?
Thank you in advance
-
This reply was modified 5 years, 5 months ago by
mdrick.
-
This reply was modified 5 years, 5 months ago by
mdrick.
-
This reply was modified 5 years, 5 months ago by
mdrick.
-
This reply was modified 5 years, 5 months ago by
mdrick.
-
This reply was modified 5 years, 5 months ago by
mdrick.
-
This reply was modified 5 years, 5 months ago by
mdrick.
First, all Relevanssi filter hook documentation is here: https://www.relevanssi.com/user-manual/filter-hooks/
All hooks are also documented in the source code.
relevanssi_excerpt_custom_field_contentis not for declaring custom fields; there’s no function for that (well, there’srelevanssi_index_custom_fields, but it applies both in indexing and in excerpts; I suppose there should be alsorelevanssi_excerpts_custom_fieldsfor filtering the actual fields). Therelevanssi_excerpt_custom_field_contentlets you filter the custom field content as a single concatenated string. That’s the only parameter, so it’s fairly basic.The difference to
relevanssi_excerpt_contentis thatrelevanssi_excerpt_contenthas all content, whilerelevanssi_excerpt_custom_field_contentonly has the custom field content, so if you want to focus on that, this is a more specific function. If you want to add content from specific custom fields (note that indexed custom fields are generally automatically used for excerpts, if you just check that option in Relevanssi settings), thenrelevanssi_excerpt_contentis better for that.To hide the links, it’s probably best to filter them out in one of these hooks.
Thank you for taking the time to explain this to me.
I’m a little confused.
What is your advice for building an excerpt with only selected custom fields (in addition to
the_contentfrom WordPress).I tried to set
Custom fieldsoption tosomeinindexingtab but I still have results with custom fields that I don’t want.I tried to set
Custom fieldstovisibleand I have these famous date fields that appear in the excerpt.-
This reply was modified 5 years, 5 months ago by
mdrick.
Relevanssi should only use the fields listed in the Custom fields setting for excerpts.
This problem does sound familiar; I seem to remember someone else having problems with ACF adding unwanted fields to the excerpts. Unfortunately that’s about all I remember of it.
What is the name of the date field that is being added to the excerpt? Are the excerpts otherwise exactly as set in the Relevanssi settings? If you disable Relevanssi custom excerpts, the date is not being added in the excerpt?
For an agenda I created two custom date fields with ACF.
A start dateevent_hour_start(datepicker) and an end dateevent_hour_end(datepicker).If I use the
someoption orvisibleI don’t have any excerpts.When I use
relevanssi_excerpt_contenthook it works but I don’t have fields in flexible content, I tried to useblocs_article_$_article_wysiwygandblocs_article_%_article_wysiwygsyntax without success. Maybe I need to reindex when I change options?If I disable Relevanssi custom excerpts (I uncheck
Create custom search result snippets). I no longer have the dates (and obviously no longer any excerpt).What if you make Relevanssi index all custom custom fields (though just
visibleshould work; ACF stores actual data in visible fields and useless metadata you don’t want to index in hidden fields), and then add this:add_filter( 'relevanssi_index_custom_fields', 'rlv_remove_dates' ); function rlv_remove_dates( $fields ) { $remove = array( 'event_hour_start', 'event_hour_end' ); return array_diff( $fields, $remove ); }Does this work? Reindexing is not necessary for changes to appear in excerpts.
It’s perfect. It works very well. Thank you to have taken the time to answer and find a solution.
I have 0 or 1 that appear at the beginning of some excerpt. Could it be because of true/false custom fields?
Yes, that does sound like a boolean field.
-
This reply was modified 5 years, 5 months ago by
The topic ‘Exclude ACF Fields in post_excerpt’ is closed to new replies.