我需要將元值從 db 檢索到我創建的自定義元框。這是我的代碼。 function wpl_owt_book_function( $book ) { define("_FILE_", "_FILE_"); wp_nonce_field( basename(_FILE_), "wp_owt_cpt_nonce"); echo "<label for='txtPublisherName'>Publisher Name</label>"; $publisher_name = get_post_meta($post->ID, "book_publisher_name" , true); echo "<input type ='text' name = 'txtPublisherName' value = '<?php $publisher_name; ?>' placeholder = 'Publisher Name' />";}文本框的結果輸出使占位符成為<?php文本框和文本框之外") placeholder = 'Publisher Name' />"任何人都可以調查這個問題并給我一個解決方案!祝你有美好的一天!
2 回答

達令說
TA貢獻1821條經驗 獲得超6個贊
你已經在 PHP 中了,所以改變這個:
echo "<input type ='text' name = 'txtPublisherName' value = '<?php $publisher_name; ?>' placeholder = 'Publisher Name' />";
至此?。▌h除 PHP 標簽)
echo "<input type ='text' name = 'txtPublisherName' value = '" . $publisher_name . "' placeholder = 'Publisher Name' />";

人到中年有點甜
TA貢獻1895條經驗 獲得超7個贊
您需要將 $post->ID 替換為 get_the_ID()。所以,更換
get_post_meta($post->ID, "book_publisher_name" , true);
和
get_post_meta(get_the_ID(), "book_publisher_name" , true);
并替換
echo "<input type ='text' name = 'txtPublisherName' value = '<?php $publisher_name; ?>' placeholder = 'Publisher Name' />";
和
echo "<input type ='text' name = 'txtPublisherName' value = '".$publisher_name."' placeholder = 'Publisher Name' />";
- 2 回答
- 0 關注
- 148 瀏覽
添加回答
舉報
0/150
提交
取消