Support » How-To and Troubleshooting » Trouble with Custom Fields/ get_post_meta_data
7 years, 1 month ago
Hi all. I’m trying to use some custom fields for content I display frequently in my posts. For example, I made a key ‘image_url’ and have tried to call it in my posts to no avail.
As far as I know, this should work:
<?php $image_url = get_post_meta($post->ID, 'image_url', true); ?>
<?php echo($image_url); ?>
I’ve also tried these:
<?php echo get_post_meta($post->ID, 'image_url', true); ?>
<?php $image_url="image_url"; echo get_post_meta($post->ID, 'image_url', true); ?>
However, WordPress successfully lists all my custom fields with the_meta so I’m not sure why I can’t display individual custom fields how I want to. None of those displays anything at all.
Is there some simple syntax error? Is there some bug in get_post_meta? Do I need to edit my functions.php, maybe?
I feel so entirely silly. Apparently, Exec-PHP wasn’t actually.. executing this PHP within my post. It works in the theme files, however.
Unless you are using a plug-in that adds the functionality, you cannot include php code in your post by entering it yourself as part of a normal post.
For more details, see this post:
Edit – above was written before second post by ladycrow