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

Home Forums Support [Resolved] custom fields (via "php in widget plugin") not displaying in Sections

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

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1048637
    Pete

    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).

    #1048873
    David
    Staff
    Customer Support

    Hi there,

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

    #1048920
    Pete

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

    #1048929
    David
    Staff
    Customer Support

    Glad to hear you got it resolved.

    #1048930
    Pete

    This solution uses a function and works well too.

    #1048932
    David
    Staff
    Customer Support

    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

    #1048933
    Pete

    You win!

    #1048999
    David
    Staff
    Customer Support

    Lol 🙂

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