[Resolved] Adding custom fields to hook element

Home Forums Support [Resolved] Adding custom fields to hook element

Home Forums Support Adding custom fields to hook element

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #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,
    Margaret

    #1956563
    Elvin
    Staff
    Customer Support

    Hi 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>
    #1956993
    Margaret

    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.

    #1957269
    David
    Staff
    Customer Support

    Hi there,

    try changing:

    <?php get_post_meta(get_the_ID(),'summary'); ?>

    to:

    <?php get_post_meta( get_the_ID(),'summary', true ); ?>

    #1957448
    Margaret

    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,
    Margaret

    #1957555
    David
    Staff
    Customer Support

    Could we get temporary admin access to the site ?

    #1957557
    Margaret

    Yes, credentials are in the private information below. Thanks so much.

    #1957826
    David
    Staff
    Customer Support

    Try 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>
    #1959129
    Margaret

    That worked perfectly! Thanks for all the help.

    #1959185
    David
    Staff
    Customer Support

    Glad to hear that!

Viewing 10 posts - 1 through 10 (of 10 total)
  • You must be logged in to reply to this topic.