猿问

Wordpress - 在 echo -html 文本框中写入 <?php ?>

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


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


祝你有美好的一天!


神不在的星期二
浏览 119回答 2
2回答

达令说

你已经在 PHP 中了,所以改变这个:echo&nbsp;"<input&nbsp;type&nbsp;='text'&nbsp;name&nbsp;=&nbsp;'txtPublisherName'&nbsp;value&nbsp;=&nbsp;'<?php&nbsp;$publisher_name;&nbsp;?>'&nbsp;placeholder&nbsp;=&nbsp;'Publisher&nbsp;Name'&nbsp;/>";至此!(删除 PHP 标签)echo&nbsp;"<input&nbsp;type&nbsp;='text'&nbsp;name&nbsp;=&nbsp;'txtPublisherName'&nbsp;value&nbsp;=&nbsp;'"&nbsp;.&nbsp;$publisher_name&nbsp;.&nbsp;"'&nbsp;placeholder&nbsp;=&nbsp;'Publisher&nbsp;Name'&nbsp;/>";

人到中年有点甜

您需要将 $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&nbsp;"<input&nbsp;type&nbsp;='text'&nbsp;name&nbsp;=&nbsp;'txtPublisherName'&nbsp;value&nbsp;=&nbsp;'<?php&nbsp;$publisher_name;&nbsp;?>'&nbsp;placeholder&nbsp;=&nbsp;'Publisher&nbsp;Name'&nbsp;/>";和echo&nbsp;"<input&nbsp;type&nbsp;='text'&nbsp;name&nbsp;=&nbsp;'txtPublisherName'&nbsp;value&nbsp;=&nbsp;'".$publisher_name."'&nbsp;placeholder&nbsp;=&nbsp;'Publisher&nbsp;Name'&nbsp;/>";
随时随地看视频慕课网APP
我要回答