- This topic has 7 replies, 3 voices, and was last updated 6 months, 3 weeks ago by
Tom.
-
AuthorPosts
-
June 23, 2020 at 11:38 am #1339234
Oleksiy
Hello,
I’d like to automatically place custom fields inside post excerpt. The fields are created by Advanced Custom Fields plugin. I discovered Elements -> Hooks, but couldn’t find any ones related to excerpt area. Is it possible to do that? I have a lot of posts and don’t want to do it manually.
Thanks a lot
June 23, 2020 at 4:30 pm #1339513Tom
Lead DeveloperLead DeveloperHi there,
If you want to attach something to an excerpt, you need to filter it like this:
add_filter( 'the_excerpt', function( $excerpt ) { $your_field = get_post_meta( get_the_ID(), 'your_field', true ); return $excerpt . $your_field; } );
Hope this helps π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentJune 24, 2020 at 4:45 am #1340025Oleksiy
Hi Tom,
Thank you for the quick response. I tried to use your code via Code Snippets plugin, but unfortunately it didn’t show me any fields, nothing at all. Am I wrong and should place this code in some other place?
There is a code I use in Elements -> Hooks and it works good, but can’t show fields inside excerpts exactly:
<p>Field name 1: <?php the_field('field-id1'); ?></p> <p>Field name 2: <?php the_field('field-id2'); ?></p>
where field-id1, field-id1 – custom field ids from ACF plugin.
Could you please in summary explain me how to create add_filter() analog and where exactly post the code?
Many thanks
June 24, 2020 at 6:27 am #1340106David
StaffCustomer SupportHi there,
can you share a link to your site, with Tom’s code added, so we can take a look ?
You can edit your original topic and use the Site URL field to share the link the privately.Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/June 24, 2020 at 8:44 am #1340421Oleksiy
Hi David,
I have a website deployed on localhost right now. After moving it to web hosting I will update the topic.
Thank you
June 25, 2020 at 3:24 am #1341167David
StaffCustomer SupportWe’ll be here π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/June 28, 2020 at 1:45 pm #1344811Oleksiy
Tom, David,
I have fixed the issue. The Tom’s code works fine, it was the fault from my end.
Many thanks for you support and fantastic Generate Press theme, especially Pro version π
June 28, 2020 at 1:55 pm #1344834Tom
Lead DeveloperLead DeveloperGlad you got it working! π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-development -
AuthorPosts
- You must be logged in to reply to this topic.