我正在尝试执行更改帖子作者和类别的功能。代码可以正常工作(假设有更改,请发布),但是wp_update_post返回“请求无效”。
这里是代码示例(无论在哪里使用,它都会以“请求无效”的任何方式返回)
<?php
define( 'WP_USE_THEMES', false );
require($_SERVER['DOCUMENT_ROOT'] .'/wp-config.php');
echo $_GET['message'];
echo ' new data: '. $data = str_replace('\"','"',$_GET['message']);
print_r( ' JSON: '. $newdata = json_decode($data, true));
echo $newauthor = $newdata['auth'];
echo $user_id = $newdata['usr'];
//$key = 'userpost2';
//if($_POST['muutto']){
echo $post1 = $newdata['muutto'];
//$post1 = 1564;
// }
// else
// {
// $post1 = get_user_meta($user_id,$key,true);
// }
echo 'testfun '.$post1.' NEWAUTHORE '.$newauthor;
$catg = 25;
//обновляем автора
kses_remove_filters();
wp_set_post_categories( $post1, $catg);
echo ' Category is ok ';
$args = array(
'ID' => $post1,
'post_author' => $newauthor,
);
$post_id = wp_update_post( $args );
if (is_wp_error($post_id)) {
$errors = $post_id->get_error_messages();
foreach ($errors as $error) {
echo $error;
}
}
kses_init_filters();
?>
以前有人遇到过这个问题吗?