Site logo

Archived topic

Header Element Template Tag Issue

10 replies · Started by Patrick on June 2, 2019

Viewing posts 1–11 of 11

Hello, I'm trying to whip up a page header for a custom post type. I'm a writer and I'm putting together a portfolio. I created a new custom post type "sample" and custom field with PODS, and I'd like to display one of the custom fields, "specialty," in the header. However, instead of the selected specialty of the sample, the header displays "Array." I'm sure it's something simple that I'm missing, but do you know what I might be doing wrong? Thanks very much.

Hi Leo, yes, that's right. It's on a dev site that's password protected. How can I get you the info?

You can send the dashboard access using Account Issue here:
https://generatepress.com/contact/

Please include the following information:
– The URL of this topic.
– Login URL.
– Username and password.

Thanks Leo. Account Issue sent.

This likely means the custom field is outputting an array, which our template tag isn't built for.

Instead, you'll want to build a shortcode:

add_shortcode( 'your_shortcode_name', function() {
    ob_start();
        
    $custom_field = get_post_meta( get_the_ID(), 'your_custom_field', true );

    foreach ( $custom_field as $field ) {
        echo $field;
    }

    return ob_get_clean();
} );

Thanks Tom. I'll give it a shot and let you know how it goes.

Hi folks, the problem was the fields I created were bidirectional relationship fields. I changed them to simple plain text and the fields now display properly.

Awesome. Thanks for sharing the solution!

So the settings are within PODs plugin I assume?

Just want to know for future reference :)

Leo, that's right. I created custom taxonomies and linked them with custom fields. Kind of a bummer they can't be linked but I kept the categories so I can still organize my samples in a couple different ways.

Thanks for reporting back!

I'm sure it will help the next user :)

This archived topic is closed to new replies.