tax_input in wp_insert_post partly not working
Try to append it in array, like this: see this: Insert post with custom taxonomy and post meta data ‘tax_input’ => array( “programmas” => array(‘Modern Family’), “zenders” => array(‘ABC’), ),
Try to append it in array, like this: see this: Insert post with custom taxonomy and post meta data ‘tax_input’ => array( “programmas” => array(‘Modern Family’), “zenders” => array(‘ABC’), ),
This is what ended up working for me: meta1='{“Length”:’ meta2=’,”Height”:”‘ meta3='”}’ while IFS=$’\t’, read -r col1 col2 col3 col4 col5 || [ -n “$col1” ] do \ meta=$meta1 meta+=$col4 meta+=$meta2 meta+=$col5; meta+=$meta3 And for meta_input line –meta_input=$meta \
You shouldn’t be getting this problem, I have a site with more 10000 posts using this function all the time and everything works fine. Try running a cleanup in your database to see if things get better.
Yeah, that would be an infinite loop. Why not have your function check to make sure that the post is something you’d actually want to insert a new cpt post for, and return if not. You’re already checking for revisions. You could easily check for your own type too.
As pointed out by Otto – it’s going to cause an infinite loop. The solution is to unhook your function before you do a wp_insert_post and then hook it back on afterwards. remove_action(‘save_post’, ‘wysiwyg_save_meta’); wp_insert_post($postArgs); add_action(‘save_post’, ‘wysiwyg_save_meta’);
I don’t know why you would want to exclude hooks as a possible solution, because I still think this is the best option OPTION 1 – without hooks To make this work, the specific URL you want to use must exist and must not return a 404. I probably think your best option here would … Read more
Your logic is a little flawed – you run isset checks on fields like title and description, but don’t actually halt the post insertion if they’re not set. You also don’t check the post_tags index, which will never exist because wp_dropdown_categories will use the field name cat unless you set it to something else. Not … Read more
If you look at the documentation for get_page_by_title, the 3rd argument is $post_type, Default: page. Since you are creating a post, you should pass in post as the post type when calling get_page_by_title, like below: if( null == get_page_by_title( $title, OBJECT, ‘post’ ) )
2020 Update: In case you landed here looking for a refresher on how to update the post’s meta, as I did, see the following edit: The post array argument in wp_insert_post() takes an inner array called meta_input, so you can create the post with proper meta in one database query. $page_id = wp_insert_post(array( ‘post_title’ => … Read more
You can attach images to a post from URI via the media_sideload_image function: $post = array(); // your post data $post_id = wp_insert_post( $post ); $url = “http://s.wordpress.org/style/images/wp3-logo.png”; $desc = “The WordPress Logo”; $image = media_sideload_image( $url, $post_id, $desc );