Support » Plugins and Hacks » Hacks » [Resolved] Changing post_parent by costum meta box

[Resolved] Changing post_parent by costum meta box

  • Hey there,

    i am searching for a method, how to edit the post_parent of a post before creating/updating the post.

    I tried the hook ‘save_post‘ which seems to be to late and called too often. I tried ‘pre_post_update‘ too, but still it does not affect the post although i get the parent’s ID right.

    Obviously I lack completely knowledge how to change the object $post before it will be inserted into the database.

    Greatful for any help provided,

Viewing 2 replies - 1 through 2 (of 2 total)
  • I found this topic named: Setting post_parent during wp_insert_post but this did not help me.

    wp_update_post( array(‘ID’ => $post_id, ‘post_parent’ => $parent) );

    Seems like i create an infinite loop.

    Anyone who can help?

    It gave me a headache, but at last i won. 😉

    For everyone who has a similar problem, try this:
    -> hook to ‘save_post
    -> write following code into the callback function
    $wpdb->get_var( $wpdb->prepare("UPDATE $wpdb->posts SET post_parent = %d WHERE ID = %d", $value, $post_id) );

    The infinite loop was created by calling a WP-post-function. This function caused ‘save_post’-hooks to be repeatedly called who themself called the WP-post-function again. Finally the request timed out.

    The solution is simple, by inserting directly with the global $wpdb class (this will not call ANY hooks!!).
    Whoever is familiar with MySQL will not need any further support on this, everyone else shouldn’t try to destroy their databases and learn MySQL-statements first.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] Changing post_parent by costum meta box’ is closed to new replies.
Skip to toolbar