Support » Fixing WordPress » Troubled by post->ID in get_post_meta (Custom Fields)
5 years, 5 months 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
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)