Site logo

Archived topic

custom fields (via "php in widget plugin") not displaying in Sections

7 replies · Started by Pete on October 30, 2019

Viewing posts 1–8 of 8

I've tried several php in page/widget plugins with the GP Sections and strangely <?php the_title(); ?> works fine but <?php echo get_post_meta($post->ID, "test", true); ?> doesn't. It looks like there's some type of glitch that is stopping the get_post_meta working inside the Sections (via the plugins).

Hi there,

WP uses global $post; to keep track of the currently viewed page. So this would need to be included in your PHP.

Great thanks. I did some Googling and found the fix on StackExchange.

Glad to hear you got it resolved.

Yep - you can also create a shortcode like so:

function get_my_post_meta() {
    global $post;
    echo get_post_meta($post->ID, "test", true);
}
add_shortcode('display_post_meta', 'get_my_post_meta');

Then you can simply add [display_post_meta] shortcode to your content without the need for the PHP widget plugin

You win!

Lol :)

This archived topic is closed to new replies.