Wordpress Custom Field Value from MoreFields not returning value
hello everyone here is the snippet of code I am having problems with...
<?php $ReleaseDate = meta('dvdReleaseDate'); ?>
If I return the value for $ReleaseDate, I get nothing...
I have also tried....
<?php $ReleaseDate = get_post_meta(get_the_I开发者_运维技巧D(), 'dvdReleaseDate', true); ?>
Nothing works..I really need help. I am using Wordpress 3.0.1. Thanks
Try to access this data at the most basic level:
<?php echo 'DVD Release Date:'.get_post_meta($post->ID, 'dvdReleaseDate', true);?>
Make sure you use this call somewhere where your $post object is accessible -- ie, within the loop. If you're using this somewhere outside the loop (for example, in functions.php), declare your $post object beforehand like this:
<?php
global $post;
echo 'DVD Release Date:'.get_post_meta($post->ID, 'dvdReleaseDate', true);
?>
If you still get no output from this, it means either:
- You are referring to your custom field by the wrong name
- This custom field has not been set for this post, or
- You are trying to use this function somewhere where your $post object is inaccessible
If #3 is in question, try something like this:
<?php
echo 'if there is data in $post, it will print here:';
print_r($post);
echo 'DVD Release Data:'.get_post_meta($post->ID, 'dvdReleaseDate', true);
?>
If your post object doesn't print, then you're experiencing #3. If it does, but there's no custom field output, it's one of the first 2.
精彩评论