0

我需要将元值从 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' />"

任何人都可以调查这个问题并给我一个解决方案!

祝你有美好的一天!

4

2 回答 2

1

你已经在 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' />";
于 2019-12-30T10:46:35.380 回答
0

您需要将 $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' />";
于 2019-12-30T13:21:40.887 回答