Php 调用未定义的函数update\u post\u meta()
我得到这个错误: 致命错误:调用未定义的函数update\u post\u meta() 我的代码如下。有人能帮我吗Php 调用未定义的函数update\u post\u meta(),php,wordpress,forms,Php,Wordpress,Forms,我得到这个错误: 致命错误:调用未定义的函数update\u post\u meta() 我的代码如下。有人能帮我吗 <?php if(isset($_POST['submit'])) { $metavalue = $_POST['usertext']; $postid = $_POST['postid']; $metakey = 'my_key'; update_post_meta( $postid, $metakey
<?php if(isset($_POST['submit']))
{
$metavalue = $_POST['usertext'];
$postid = $_POST['postid'];
$metakey = 'my_key';
update_post_meta( $postid, $metakey, $metavalue );
} ?>
<div class="wrap">
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="hidden" name="postid" value="<?php echo $_GET['value'] ?>" >
<input type="hidden" name="123" value="123" >
<input type="text" name="usertext">
<br/>
<input type="submit" name="submit" value="Update">
</form>
</div>
<?php
我猜这是某种主题。您需要为全局$post
变量分配一个post
试一试
基于某种变量获取post,或者如果不给它任何值,则返回false
是保持当前职位的WP全局变量。使用时要小心,因为如果假设循环自动继续,或者如果需要的话,它可能会打乱代码
设置全局post数据。帮助设置自定义查询结果的格式以使用模板标记
希望这能帮到你。下次提问时,请查看和。您的代码位置在哪里?在可湿性粉剂模板内?
//your stuff until here
$metakey = 'my_key';
$current_post = get_post($_POST['postid']);
if($current_post){
global $post = $current_post
setup_postdata($post);
update_post_meta( //continue
//more continueing
} else {
//throw some error
}