Upload image and assign it’s id to post

WordPress attachments are saved in the wp_posts table with the post_type field set to ‘attachment’. The post id for the post that the attachment is ‘linked’ to is in the post_parent field. Keep in mind that an attachment being ‘linked to a post is not really a solid connection. It is very possible to have … Read more

How to use `wp_insert_user` & `wp_insert_post` simultaneously without `headers already sent` error?

The header problem is actually this problem: Warning: mysql_real_escape_string() expects parameter 1 to be string, object given in /home/wp-includes/wp-db.php on line 885 Warning: mysql_real_escape_string() expects parameter 1 to be string, object given in /home/wp-includes/wp-db.php on line 885 You are getting those errors because somewhere you are sending an object when you shouldn’t be. When that … Read more

Inserting post_id into guid before wp_insert_post

Why would you need that? ID in a database is auto increment – it manages it’s value itself. If your target is to set custom guid, you should update the inserted post as soon as it is created via wp_update_post right after your $post_id = wp_inserted_post($mypost); like this: …Your code above… $postid = wp_insert_post($mypost); $data … Read more

Front end posting

You can not use wp_redirect() if the headers have already been sent so snippet you provided should not be used within your template files, instead you should wrap it within a function and place it into your functions.php file and hook onto template_redirect action. Example: add_action(‘template_redirect’, ‘front_end_post’, 99); function front_end_post() { if( ‘POST’ == $_SERVER[‘REQUEST_METHOD’] … Read more

wp_insert_post creating duplicate post with Safari

You could try to use nonces (http://codex.wordpress.org/WordPress_Nonces) in your requests,so even if the request is being sent many times, only 1 time is being saved. You can add in your form this line <form method=”POST”> <input type=”hidden” name=”nonce” value=”<?php echo wp_create_nonce( ‘form-nonce’ );?>” /> …. </form> and in the code where you check : $nonce … Read more

Insert posting automatically based in acf field

Before inserting check if post exists: $exists = get_page_by_title( get_field(‘fornecedor’), OBJECT, ‘fornecedores’); if ( empty( $exists ) ) { wp_insert_post( array( ‘post_status’ => ‘publish’, ‘post_type’ => ‘fornecedores’, // post_type which is created posting ‘post_title’ => get_field(‘fornecedor’), // Custom field to generate the post type ‘post_content’ => ” ) }

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