Is it possible to create a post using a metabox?

Update The answer is so simple, I couldn’t see it at first. 🙂 Just remove the action during the first function call. This way, your work within the API, and your function is really called just once. No need for static or even global variables or constants. function my_metabox_save() { remove_action( ‘save_post’, ‘my_metabox_save’ ); // … Read more

Conditionally set post_content in wp_insert_post

I can’t help but think I am missing something but what seems like the obvious answer is to alter your $create_pages array: $create_pages = array( ‘one’ => ‘content for one’, ‘two’ => ‘content for two’, ‘three’ => ‘content for three’ ); foreach ($create_pages as $title => $content) { $add_pages = array( ‘post_title’ => $title, ‘post_content’ … Read more

Contact Form 7 to featured image

Thanks @Judd Franklin for the directions. I was also missing $submission->uploaded_files();. Here is the working code for those who are looking for the same answer: function image_form_to_featured_image( $contact_form ) { $submission = WPCF7_Submission::get_instance(); $posted_data = $submission->get_posted_data(); // Creating a new post with contact form values $args = array( ‘post_type’ => ‘projects’, ‘post_status’=> ‘draft’, ‘post_title’=> wp_strip_all_tags( … Read more

wp_insert_post returns int(0)

According to the notes on the codex wp_insert_post() post_title and post_content are required If you want the content to be empty, you can write your wp_insert_post args array thus: $postID = wp_insert_post(array( “post_title” => $name, “post_status” => “publish”, “post_content => ” “, “post_type” => “mycustomposttype”, ), true);

wp_insert_post works, but the post isn’t visible in the admin post list or front end

The problem is $postarr[“post_status”] = “published”; you should change it to $postarr[“post_status”] = “publish”; // Set it to ‘publish’, not ‘published’ Now, this is a bit off topic, but you may want to omit the following (those are created by the wp_insert_post() by default): $postarr[“post_date_gmt”] = date(‘Y-m-d H:i:s’, time()); $postarr[“post_date”] = date(‘Y-m-d H:i:s’, time()); $postarr[“post_modified”] … Read more

How to add multiple product gallery images from front-end

if ( ! empty( $_FILES[‘muti_files’] ) ) { $files = $_FILES[‘muti_files’]; foreach ($files[‘name’] as $key => $value){ if ($files[‘name’][$key]){ $file = array( ‘name’ => $files[‘name’][$key], ‘type’ => $files[‘type’][$key], ‘tmp_name’ => $files[‘tmp_name’][$key], ‘error’ => $files[‘error’][$key], ‘size’ => $files[‘size’][$key] ); } $_FILES = array(“muti_files” => $file); $i=1; foreach ($_FILES as $file => $array) { if ($_FILES[$file][‘error’] !== … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)