Site logo

[Resolved] Is there a way to insert a custom field in a custom template?

Home Forums Support [Resolved] Is there a way to insert a custom field in a custom template?

Home Forums Support Is there a way to insert a custom field in a custom template?

Viewing 10 posts - 1 through 10 (of 10 total)
  • Author
    Posts
  • #2441487
    gpstart

    I have a custom post type with custom fields attached to it.

    I want to create a custom template and add those custom fields to it.

    Is there documentation for this?

    If not, can someone please outline the steps to carry this out?

    I am using Metabox for the custom fields and custom post type.

    Thanks.

    #2441549
    David
    Staff
    Customer Support

    Hi there,

    to begin with you need to create your single template and content template.

    The simplest option is to follow the steps provided here:

    https://docs.generatepress.com/article/setting-up-a-simple-custom-post-type/

    However if you want to build the template using a Block Element, then let me know as Step 3 will need to be different. Let me know.

    #2441713
    gpstart

    Just want to check, because I mentioned I created my custom post type using Metabox, but, I edited my post. Not sure if you responded before I edited it or after.

    So, creating the post type using Metabox is of no use? I still need to follow the above instructions?

    #2441979
    Ying
    Staff
    Customer Support

    If the CPT has already been created using a plugin, then you don’t need to create it again.

    You can start to create the template using block element - content template:
    https://docs.generatepress.com/article/block-element-content-template/

    Make sure GenerateBlocks plugin is installed, so you can use its dynamic data feature to pull the custom field’s value:
    https://docs.generateblocks.com/article/headline-overview/#dynamic-data

    #2443536
    gpstart

    Thanks. But, I still can’t find how to insert a custom field.

    I tried using a Headline and it offers me a Dynamic Text Type.

    I tried using a Button and it offers me a Dynamic Text Type and Dynamic Link Type.

    In the options above, I don’t see any option for a custom field.

    See image:

    Based on the second link you provided, I saw in the sidebar an option to enable Dynamic Data. I did that and then I could select the Data Source of my post type (called Brand). That looks good. But, then I have to select a specific Brand from my custom post type. I don’t want to have to select a specific Brand. I want this to apply to all Brand posts.

    Is this the way it’s supposed to work?

    #2443755
    Fernando
    Customer Support

    Hello there,

    I believe you have the wrong Dynamic setting which is why it’s not working as expected. If you’re trying to show a post meta field through a Headline Block specific to all “Brand” Posts, try setting the Data Source to Current Post, the Content Source to Post Meta, and the Post Meta Field to the field name set in Metabox.

    Example: https://share.getcloudapp.com/04uyrYzk

    This setup should grab the specific Post Meta dynamically on all brands you have if I’m understanding your structure correctly.

    Let us know how it goes.

    #2443788
    gpstart

    Thank you Fernando, that worked!

    However, after I implemented it, it replaced the content of what was originally in the specific brand post.

    My intention was to add these custom fields, created for my Brand posts, to the end of the content.

    I noticed that there is a “Post Content” block. And I included that before including the custom fields. And that seemed to fix it.

    It looks right. Just want to check if that would that be the right way to implement this: That is to add custom fields to the end of the Brand post.

    Not sure if there is a “better” way of doing it. For example, the original way I did it, it replaced my content. Is there a way for it to get added to the bottom of each Brand post as opposed to having to use the “Post Content” block.

    #2443814
    Fernando
    Customer Support

    I see. Glad that worked.

    Yes, using a Content Template with a Post Content Block is one way to do it.

    Another way, as opposed to using a Content Template, is to just use a Block Element – Hook. Hook it to before_footer or somewhere you prefer. See here for some hooks you can try: https://docs.generatepress.com/article/hooks-visual-guide/

    With this, you wouldn’t need a “Post Content” Block. You’re just basically injecting the custom fields at the bottom of each “brand”.

    Reference: https://docs.generatepress.com/article/block-element-hook/

    #2444289
    gpstart

    Thank you very much. I’m so glad I found GeneratePress. I just started using it and it’s pretty amazing, including the support.

    #2445859
    Fernando
    Customer Support

    You’re welcome! We’re glad you’re enjoying our Product! Thank you for your appreciation!

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