- This topic has 9 replies, 3 voices, and was last updated 4 years, 4 months ago by
David.
-
AuthorPosts
-
October 7, 2021 at 2:04 pm #1956474
Margaret
Hello,
I am trying to add a “summary” paragraph to the top of each blog post.
I created a custom field called “summary,” inserted the paragraph, and saved the post.
I created a hook with the following code:
<div class="blog_post_summary"> <p> <b>Summary: </b>{{custom_field.summary}} </p> </div>Under settings, I set to “generate_before_content.” I enabled “Execute Shortcodes” and “Execute PHP.”
Under Display Rules, I set to display on all Posts.
However, on the actual post, it is displaying as “Summary: {{custom_field.summary}}” and is not populating the custom field.
Thanks,
MargaretOctober 7, 2021 at 5:10 pm #1956563Elvin
StaffCustomer SupportHi Margaret,
{{custom_field.summary}}is a pattern used for template tags which only works on Header Elements.For Hook elements, you’ll have to enable “Execute PHP” and fetch the field using PHP codes.
Example:
<div class="blog_post_summary"> <p> <b>Summary: </b><?php get_post_meta(get_the_ID(),'summary'); ?> </p> </div>October 8, 2021 at 6:17 am #1956993Margaret
Hi Elvin, thanks so much for your help. I added that code to the Hook element and made sure “Execute PHP” is enabled.
It is displaying as just “Summary: ” but the Value I entered in the Post Custom Fields isn’t displaying.
October 8, 2021 at 8:10 am #1957269David
StaffCustomer SupportHi there,
try changing:
<?php get_post_meta(get_the_ID(),'summary'); ?>to:
<?php get_post_meta( get_the_ID(),'summary', true ); ?>October 8, 2021 at 10:57 am #1957448Margaret
Hi David, thanks for your help. I updated the PHP code as you suggested above but I’m still getting the same result. At the top of the post, it says “Summary: ” but the Value from the Custom Field isn’t displaying.
Best,
MargaretOctober 8, 2021 at 1:38 pm #1957555David
StaffCustomer SupportCould we get temporary admin access to the site ?
October 8, 2021 at 1:43 pm #1957557Margaret
Yes, credentials are in the private information below. Thanks so much.
October 9, 2021 at 2:46 am #1957826David
StaffCustomer SupportTry this instead:
<?php $summary = get_post_meta( get_the_ID(),'summary', true ); ?> <div class="blog_post_summary"> <p><b>Summary: </b><?php echo $summary; ?></p> </div>October 10, 2021 at 9:51 am #1959129Margaret
That worked perfectly! Thanks for all the help.
October 10, 2021 at 10:49 am #1959185David
StaffCustomer SupportGlad to hear that!
-
AuthorPosts
- You must be logged in to reply to this topic.