• i am developing in functions.php a function which, when a post in a certain category is created/edited, will create also a related page or update it if already exists.

    The creation of a new page with wp_insert_post works like a charme, but if the page already exists (after else statement) and use wp_update_post instead, WordPress returns just a blank screen and doesn’t update the post and neither the page.

    I can’t figure out why, define('WP_DEBUG', true); doesn’t return any hint.

    `$page_check = get_page_by_title($promo_page_title);
    if(!isset($page_check->ID)){
    $new_page = array(
    ‘post_type’ => ‘page’,
    ‘post_title’ => $promo_page_title,
    ‘post_content’ => $promo_page_content,
    ‘post_status’ => ‘publish’,
    ‘post_author’ => 1,
    ‘post_parent’ => 27
    );
    $new_page_id = wp_insert_post($new_page);
    if($new_page_id){
    update_post_meta($new_page_id, ‘_wp_page_template’, ‘page_promo.php’);
    $pids[0] = $new_page_id;
    } else {
    $e = TRUE;
    wp_die(‘Error creating promo page’);
    }
    }
    else {
    $new_page = array(
    ‘ID’ => $page_check->ID,
    ‘post_type’ => ‘page’,
    ‘post_title’ => $promo_page_title,
    ‘post_content’ => $promo_page_content,
    ‘post_status’ => ‘publish’
    ‘post_author’ => 1,
    ‘post_parent’ => 27
    );
    $new_page_id = wp_update_post( $new_page );
    if($new_page_id){
    update_post_meta($new_page_id, ‘_wp_page_template’, ‘page_promo.php’);
    $pids[0] = $new_page_id;
    } else {
    wp_die(‘Error updating promo page’);
    }
    }
    unset($promo_page_content);`

    Thanks for your help!

    • This topic was modified 8 years, 1 month ago by simonquasar.
  • The topic ‘wp_update_post() blank screen’ is closed to new replies.