[Support request] custom field display in layout

Home Forums Support custom field display in layout

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #895020
    chete

    Hi, I created a cpt to add new information. For the entries of this new cpt I have created a custom field, a gallery.
    I’ve created a layout for this cpt but I can’t get the custom field to be displayed.

    I have tried
    <h1>
    {{post_title}}
    </h1>
    <br>
    {{custom_field.galeria}}

    or
    <?php the_field(‘galeria’): ?>

    Regards

    #895106
    David
    Staff
    Customer Support

    Hi there,

    how have you created the Custom Field Galeria?
    And is this being added to the GP Header Element?

    #895360
    chete

    Hi David
    I created the cpt by adding a snippet, and the custom field with Elliot Condon’s ACF pro plugin.
    http://prntscr.com/nmveyj
    Yes, I have created a new header in GP, put only for the pages of that CPT
    http://prntscr.com/nmvf9d

    Regards

    #895766
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    This should do it:

    {{custom_field.galeria}}

    However, that assumes that galeria is the name of the custom field. I’m not sure if ACF prefixes their custom fields with anything?

    #896012
    chete

    Yes, I tested that because I thought it would work, but it wouldn’t. If I put that, it shows me only the word Array

    Regards

    #896363
    Tom
    Lead Developer
    Lead Developer

    Ah, so it returns an array of data instead of a string.

    You might need to create a shortcode to output it:

    add_shortcode( 'galeria', function() {
        $galeria = get_post_meta( get_the_ID(), 'galeria', true );
    
        if ( $galeria ) {
            foreach ( (array) $galeria as $item ) {
                echo $item;
            }
        }
    } );

    Then you could use the [galeria] shortcode.

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