• Resolved bobblah

    (@bobblah)


    I have set up a form on the front end that allows a user to upload content which creates a new post in the backend.

    The problem is the post it creates is a custom post type that has a parent page. And this particular bit of code which gets the parent page and hooks the post to the parent is not working: $_POST[“post_parent”];

    If I delete that code and put in ’15’ for example, it works fine the new post is a child of page 15.

    I swear at one point this code was working but it no longer does. Is there any reason beyond the obvious this code won’t work here, inside this function when the save form function is called?

    if (isset($_REQUEST["submit_action"]) && $_REQUEST["submit_action"]=="save") {
    
    	$nonce = $_REQUEST['_wpnonce'];
    	if (! wp_verify_nonce($nonce, 'subpost') ) wp_die("You do not have permission to do that.");
    
    	if (isset($_POST['form_submit']) && $_POST['form_submit']=="Move to Trash") {
    
        	$post_id = 0;
    		$post_id = (int) $_POST["ID"];
    		if ($post_id > 0) {
    			$post = get_post($post_id);
    		}
    		$result = wp_trash_post($post->ID);		
    
    	} else {
    
    		// save and return with JavaScript
    		$post_id = 0;
    		$post = new stdClass;
    		$post->ID = 0;
    		if (isset($_POST["ID"])) {
        		$post_id = (int) $_POST["ID"];
            }
    		if ($post_id > 0) {
    			$post = get_post($post_id);
    		}
    		if($post->ID == 0) {
    			$post->post_status = 'publish';
    		}
    
    		$post->post_title = $_POST["post_title"];
    		$post->post_content = $_POST["post_content"];
    		$post->post_type = 'exhibitions';
    		$post->post_parent = $_POST["post_parent"];
    		$post->ID = wp_insert_post($post);
    		$pid = wp_insert_post($post);
    
    		// TO DO -- save custom fields
    
    		do_action('subpost_save_form_fields',$post);
    		if ($_FILES) {
    			foreach ($_FILES as $file => $array) {
    			$newupload = insert_attachment($file,$pid);
    			}
    		}
    	}
    }
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Child page not attaching to parent – PHP $_POST["post_parent"]; not working’ is closed to new replies.