WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. egoipse
    Member
    Posted 2 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. alchymyth
    The Sweeper & Moderator
    Posted 2 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