我需要将元值从 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' />";
至此!(删除 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 关注
- 118 浏览
添加回答
举报
0/150
提交
取消