get post parent id
-
Hi.
I’m trying to set the post parent, without knowing the post parent id, rather trying to set it by name. After the array has been inserted wp_insert_post, I’m trying to use the parent id to update_post_meta for the parent, as the child is added.Here’s the code snippet:
$create_record_fields = array( 'post_type' => 'records', 'post_status' => 'publish', 'post_category' => array(20), 'post_parent' => $_POST["item-name"], 'post_title' => $count + 1, 'student_name' => $_POST["student_name"], 'student_id' => $_POST["student_id"], 'todays_date' => $_POST["todays_date"], 'due_date' => $_POST["due_date"], 'return_date' => $_POST["return_date"] ); if (isset($_POST["submit"])) { $new_post_id = wp_insert_post($create_record_fields); $parent_id = wp_get_post_parent_id($new_post_id); echo $parent_id; update_post_meta( $new_post_id, 'wpcf-item-name', $_POST["item_name"] ); update_post_meta( $new_post_id, 'wpcf-student_name', $_POST["student_name"] ); update_post_meta( $new_post_id, 'wpcf-borrow-record-id', $count + 1 ); update_post_meta( $new_post_id, 'wpcf-duedate', $due_date); update_post_meta( $new_post_id, 'wpcf-student-id', $student_id); update_post_meta( $new_post_id, 'wpcf-returndate', $_POST["return_date"]); update_post_meta( $new_post_id, 'wpcf-borrowdate', $today); update_post_meta( $new_post_id, 'wpcf-equipment-items', $_POST["item_name"]); wp_set_object_terms( $new_post_id, 'borrow_records', 'record_types'); update_post_meta($parent_id, 'wpcf-status', $_POST["status"]); }
the post data comes from here:
while ( have_posts() ) : the_post(); // Include the page content template. get_template_part( 'content', 'page' ); ?> <form name="create_record" method="post" action=""> <ul> <li>Student Name:<input type="text" name="student_name"></input></li><br> <li>Item Name:<input type="text" name="item_name"></input></li><br> <li>Item Status:<br> <input type="radio" name="status" value="1">In<br> <input type="radio" name="status" value="2">Out<br> <input type="radio" name="status" value="3">Broken<br> </li> <li>Return Date:<input type="text" name="return_date"></input></li><br> <li>Checkout Staff:<input type="text" name="checkout_staff"></input></li><br> <li>Checkin Staff:<input type="text" name="checkin_staff"></input></li><br> <input name='submit' type='submit'> </ul> </form> <?php
- The topic ‘get post parent id’ is closed to new replies.