The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

Troubled by post->ID in get_post_meta (Custom Fields) (2 posts)

  1. egoipse
    Posted 4 years ago #

    I have the following problem which it's easy to solve applying simple knowledge of PHP, which I haven't.

    I can call a custom field in my theme code with the following php code:

    < ?php $key="Fecha"; echo get_post_meta($post- >ID, $key, true); ? >

    But if I insert the same code in a post, it doesn't work. When the post is published, it appears as text everything that is displayed after "->": ID, $ key, true);?>

    Therefore, I assume that the "->" is acting as code closing command.

    I've tried other alternatives: "- >", " ->" and so on. But the outcoming is the same.

    I also tried declaring the variable $postid before, but no success either:

    < ?php $postid = get_the_ID(); $key="Fecha"; echo get_post_meta($postid, $key, true); ? >

    Any help will be welcomed

  2. Michael
    Forum Moderator
    Posted 4 years ago #

    php code does not work in post content;

    you need to use a plugin such as http://wordpress.org/extend/plugins/exec-php/ (there might be other plugins that do the same)

Topic Closed

This topic has been closed to new replies.

About this Topic