如果检查错误通知中的行,则应在WP 4.9.1中找到该函数的用法array_filter
, 需要一个数组作为参数(see the code).您的post数组中的值需要一个数组\'post_category\'
, 当前为字符串。
来自WP核心的来源:
* @type array $post_category Array of category names, slugs, or IDs.
* Defaults to value of the \'default_category\' option.
在您的源代码示例中,您应该更改它,它应该可以工作,
\'post_category\' => array( $_POST[\'cat\'] ),
.
// Add the content of the form to $post as an array
$post = array(
\'post_title\' => wp_strip_all_tags( $title ),
\'post_content\' => $description,
\'post_category\' => array( $_POST[\'cat\'] ), // Usable for custom taxonomies too
\'tags_input\' => $tags, // Need an array
\'post_status\' => \'draft\', // Choose: publish, preview, future, etc.
\'post_type\' => \'listings\', // Use a custom post type if you want to
);
wp_insert_post( $post );