Site logo

Archived topic

custom field display in layout

5 replies · Started by Ignacio on May 10, 2019

Viewing posts 1–6 of 6

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

Hi there,

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

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?

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

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.

This archived topic is closed to new replies.