簡體   English   中英

來自MoreFields的Wordpress自定義字段值未返回值

[英]Wordpress Custom Field Value from MoreFields not returning value

你好,這里的每個人都是我遇到問題的代碼片段...

<?php $ReleaseDate = meta('dvdReleaseDate'); ?>

如果我返回$ ReleaseDate的值,我什么也不會得到...

我也嘗試過...

<?php $ReleaseDate = get_post_meta(get_the_ID(), 'dvdReleaseDate', true); ?>

什么都沒有。.我真的需要幫助。 我正在使用Wordpress 3.0.1。 謝謝

嘗試在最基本的級別上訪問此數據:

<?php echo 'DVD Release Date:'.get_post_meta($post->ID, 'dvdReleaseDate', true);?>

確保在可訪問$ post對象的地方(即在循環內)使用此調用。 如果在循環之外的某個地方使用此函數(例如,在functions.php中),請事先聲明$ post對象,如下所示:

<?php 
global $post;
echo 'DVD Release Date:'.get_post_meta($post->ID, 'dvdReleaseDate', true);
?>

如果仍然沒有得到任何輸出,則意味着:

  1. 您使用錯誤的名稱指代自定義字段
  2. 尚未為此帖子設置此自定義字段,或者
  3. 您試圖在無法訪問$ post對象的地方使用此功能

如果#3有問題,請嘗試以下操作:

<?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);
?>

如果您的post對象沒有打印,則說明您遇到了#3。 如果可以,但是沒有自定義字段輸出,則為前兩個輸出之一。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM