Insert multiple posts as parent of the first

If I understand you correctly, this should work: $first_post = true; $post_parent = 0; foreach ( $books as $book ) { $post = array( ‘post_title’ => esc_html__( ‘Post’, ‘book-cpt’ ), ‘post_content’ => ‘test’, ‘post_status’ => ‘publish’, ‘post_type’ => ‘book’, ‘post_parent’ => $post_parent ); $book_id = wp_insert_post( $post ); if ($first_post) { $post_parent = $book_id; $first_post … Read more

$wpdb->insert() doesnt work anymore

examine below example and figure out what is wrong with your code. global $wpdb; if(isset($_POST[‘submit’])) { $table_name = $wpdb->prefix.’employee’; $wpdb->insert( $table_name, array( ‘first_name’=>$fname, ‘last_name’=>$lname), array( ‘%s’,’%s’ ) ); use global $wpdb; global $wpdb; $table_name = $wpdb->prefix.’rdp_banners’; $wpdb->insert( $table_name, array( ‘banner_id’ => $banner_id, ‘rdp_banner’ => $rdp_banner, ‘banner_type’ => $banner_type, ‘customer_id’ => $customer_id, ‘status’ => $status, ‘company_name’ … Read more

$wpdb->insert() does not insert fields

I found the problem. Apparently with the new WP update if you try to insert into a VARCHAR column and the column length is less than what you are trying to insert it just won’t work. Prior to this update it will insert it but trim off the excess characters.

Returning all values from foreach in function php [closed]

Try this: function returncartdata($data) { $return = ”; foreach ($data as $carthtml => $itemhtml) { $return .= $itemhtml[0]; $return .= $itemhtml[1]; $return .= $itemhtml[2]; $return .= $itemhtml[3]; $return .= $itemhtml[4]; } return $return; } $rawhtmlcartdata = cart_items_array(); $ordercart = returncartdata($rawhtmlcartdata); wp_insert_post(array ( ‘post_type’ => ‘saved-orders’, ‘post_title’ => ‘Test’, ‘post_content’ => $ordercart, ‘post_status’ => ‘publish’, ‘comment_status’ … Read more

get post id from wp_insert_post for get_template_part

Declare $my_post_id as global in your code. Declare $my_post_id as global in the-post.php template. Your code: global $my_post_id; $my_post = array( ‘post_type’ => ‘theposttt’, ‘post_title’ => ‘test’, ‘post_content’ => ”, ‘post_status’ => ‘publish’, ‘post_author’ => 1 ); $my_post_id = wp_insert_post($my_post); if(is_wp_error($my_post_id)) $my_post_id = 0; Now, you can use $my_post_id in the-post.php template. Possible values: 0 … Read more

Add new post in existing categories using wp_insert_post

post_category is only for Core Categories. Use tax_input instead: $new_post = array( ‘post_title’ => esc_attr(strip_tags($title)), ‘post_content’ => esc_attr(strip_tags($description)), ‘post_type’ => ‘proiecte’, ‘post_status’ => ‘publish’, ‘tax_input’ => array( ‘categorie’ => array(17,16) ) ); $post_id = wp_insert_post($new_post); It may be clearer to other developers, and yourself in the future, if you use something other than categorie – … Read more

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