Black Friday Sale! Get up to $40 off GP Premium!Learn more

[Support request] Custom Fields In Post – Like in Header

Home Forums Support Custom Fields In Post – Like in Header

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #484062
    Stephen

    Hello Tom,

    How can I get custom fields to show up in a custom post I created for uploading sermons to my site, the same way they do in the site header.
    For example the header has these template tags: {{post_title}} {{post_date}} {{post_author}} {{post_terms.taxonomy}} {{custom_field.name}}.

    I have a custom post type that I made with CPT UI, and I created custom fields with ACF to get all the info into my “Sermon” post that I need; but I cannot figure out how to get the info that I entered into the custom fields to show up in my “Sermon” posts.

    I would like to be able to add the custom fields to my post like this:

    {{custom_field.minister_name}} / {{custom_field.date_preached}} / {{custom_field.location}}.

    If there is a better way to go about this altogether, feel free to let me know – I am new to all of this.

    Stephen Hale
    Aspiring Web Designer

    GeneratePress 2.0.2
    #484147
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    So you’re wanting that custom field to show up within your actual post content, not the Page Header?

    You would likely need to create a shortcode.

    For example:

    add_shortcode( 'sermon', 'tu_sermon_shortcode' );
    function tu_sermon_shortcode() {
        if ( get_post_meta( get_the_ID(), '_your_custom_field', true ) ) {
            return get_post_meta( get_the_ID(), '_your_custom_field', true );
        }
    
        return '';
    }

    Not tested, but should work in theory.

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