开发者

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:

  1. You are referring to your custom field by the wrong name
  2. This custom field has not been set for this post, or
  3. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜