insert category from form in a post

You need to create the category first, then add it to the post: $my_post = array(); $my_post[‘post_author’] = $userid; $my_post[‘post_title’] = $name; $my_post[‘post_name’] = str_replace(‘ ‘, ‘-‘, $name); $cat_id = wp_create_category($_POST[‘postcats’], 0); // we create the category and we get the ID, the 0 is for no parent category $my_post[‘post_category’] = array($cat_id);//this value is an … Read more

How can I automatically add a post with Latin characters?

htmlspecialchars() only converts &, “, ‘, < and >. To also convert (encode, really) accented characters, you need to use htmlentities(), and depending on the rest of your setup you may also have to specify which encoding to use. So: $content = htmlspecialchars( $text, ENT_QUOTES|ENT_SUBSTITUTE, ‘UTF-8’ ); (Substitute ‘ISO-8859-1’ for ‘UTF-8’ if necessary, though it … Read more

wp_insert_post order problem

I found a solution. I just set my own value for the “post_date” field in the wp_insert_post function. As an example: $time = time(); for ($i=0; $i < count($postArgs); $i++) { $postArg = $postArgs[$i]; $postArg[‘post_date’] = $time-$i; wp_insert_post($postArg); }