繁体   English   中英

WordPress - 写<?php ?>在 echo -html 文本框内

[英]Wordpress - Write <?php ?> inside echo -html text box

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

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

祝你有美好的一天!

你已经在 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' />";

您需要将 $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' />";

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM