On save_post need to wp_insert_post and save partent post id to child post and child post id to parent post

Here’s an updated version of your code: add_action(‘save_post’, array($this, ‘save_post_type_example_meta_boxes’)); function save_post_type_example_meta_boxes($post_id) ………. if (…) { $new_custom_post = array( ‘post_title’ => $title, ‘post_content’ => ”, ‘post_status’ => ‘publish’, ‘post_author’ => 1, ‘post_type’ => ‘custom_post_type’, ‘meta_input’ => array( ‘meta_1’ => ‘X’, ‘parent_post_id’ => $post_id, ), ); // Prevent this action from running twice. remove_action( ‘save_post’, [ … Read more

Meta inserted through wp_insert_post gets messed up

So I ended up just adding the meta after inserting the post, which doesn’t give any error. It bypasses the problem without explaining it though… $postarr = array( ‘post_title’ => $link[‘caption’], ‘post_type’ => ‘ct_external_link’, ‘post_status’ => ‘publish’, ‘post_excerpt’ => $link[‘caption’], ); $external_link_id = wp_insert_post($postarr); if( !empty($external_link_id) ) { add_post_meta($external_link_id, ‘ct_external_link_url’, $doc[‘file’], true); if( isset($doc[‘hide’]) ) … Read more

permalink not showing correctly using wp_insert_post and post_name

AH! https://permalinkmanager.pro/docs/tutorials/how-to-remove-numbers-2-3-appended-to-the-permalinks/ So the automatic slug creation of -2, -3, ..etc is done by core in order to make slugs unique. But I knew there was a way to change the permalink and not the slug. I just couldn’t find code anywhere to do this so I resorted to using this premium plugin. global $permalink_manager_uris; … Read more

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