wp_insert_post() infinit loop PHP Warning: in_array() expects parameter 2 to be
-
Hi this is my first post so apologies if something is not right.
I’m using wp_insert_post to take the html of a file and automatically create a post. I have a function that searches a directory, opening and extracting the correct html. The files have dates (which is why i use the subsrt() below). The html is a string, as is anything else I would use for content.
<?PHP require_once(dirname(__FILE__)."/createpost.php"); $dir = dirname(__FILE__)."/html"; $files = scandir($dir); $date = (string) date("Ymd"); foreach($files as $value){ if((substr($value,5,8)) == $date){ $html = file_get_contents($dir."/".$value); createpost($value, $html); } }
The above works. below is the createpost().
<?php function createpost($post_title, $post_content){ require_once("/var/www/wp-load.php"); $mypost = array( 'ID' => $post_id,//[ <post id> ] //Are you updating an existing post? 'menu_order' => $menu_order,//[ <order> ] //If new post is a page, it sets the order in which it should appear in the tabs. 'comment_status' => $comment_status,//[ 'closed' | 'open' ] // 'closed' means no comments. 'ping_status' => $ping_status,//[ 'closed' | 'open' ] // 'closed' means pingbacks or trackbacks turned off 'pinged' => $pinged,//[ ? ] //? 'post_author' => $post_author,//[ <user ID> ] //The user ID number of the author. 'post_category' => $post_category,//[ array(<category id>, <...>) ] //post_category no longer exists, try wp_set_post_terms() for setting a post's categories 'post_content' => "[raw]\n\n".$post_content."\n\n[/raw]",//[ <the text of the post> ] //The full text of the post. 'post_date' => $post_date,//[ Y-m-d H:i:s ] //The time post was made. 'post_date_gmt' => $post_date_gmt,//[ Y-m-d H:i:s ] //The time post was made, in GMT. 'post_excerpt' => $post_excerpt,//[ <an excerpt> ] //For all your post excerpt needs. 'post_name' => $post_name,//[ <the name> ] // The name (slug) for your post 'post_parent' => $post_parent,//[ <post ID> ] //Sets the parent of the new post. 'post_password' => $post_password,//[ ? ] //password for post? 'post_status' => 'private',//[ 'draft' | 'publish' | 'pending'| 'future' | 'private' | 'custom_registered_status' ] //Set the status of the new post. 'post_title' => $post_title,//[ <the title> ] //The title of your post. 'post_type' => $post_type,//[ 'post' | 'page' | 'link' | 'nav_menu_item' | 'custom_post_type' ] //You may want to insert a regular post, page, link, a menu item or some custom post type 'tags_input' => $tags_input,//[ '<tag>, <tag>, <...>' ] //For tags. 'to_ping' => $to_ping,//[ ? ] //? 'tax_input' => $tax_input//[ array( 'taxonomy_name' => array( 'term', 'term2', 'term3' ) ) ] // support for custom taxonomies. ); // Insert the post into the database wp_insert_post( $mypost ); } ?>
when this is all run, i get the following infinite error and the post is never created:
PHP Warning: in_array() expects parameter 2 to be array, null given in /var/www/wp-includes/kses.php on line 1146
PHP Warning: in_array() expects parameter 2 to be array, null given in /var/www/wp-includes/kses.php on line 1146
PHP Warning: in_array() expects parameter 2 to be array, null given in /var/www/wp-includes/kses.php on line 1146….If I comment out or change the content of the html file this runs fine. It looks like there is something in the html, but regardless of the files contents it is being seen as a string. What does this warning refer to? Any ideas on getting around it?
Corey
- The topic ‘wp_insert_post() infinit loop PHP Warning: in_array() expects parameter 2 to be’ is closed to new replies.