Ready to get started?Download WordPress


Trouble with Custom Fields/ get_post_meta_data (3 posts)

  1. ladycrow
    Posted 4 years 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?

  2. ladycrow
    Posted 4 years ago #

    I feel so entirely silly. Apparently, Exec-PHP wasn't actually.. executing this PHP within my post. It works in the theme files, however.

  3. jonradio
    Posted 4 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic