wp_insert_post() White Screen / Blank Page












1















I am creating a custom post from a front end form.
The post is successfully created but leading to white screen where the form is implemented.



Here is my code:-



$new_post_args = array(
'post_title' => 'Lead is being updated',
'post_status' => 'publish',
'post_type' => 'hg-rma',
'post_author' => 4470,
);

$post_id = wp_insert_post($new_post_args);
if($post_id)
{
$update_post_args = array(
'ID' => $post_id,
'post_title' => $post_id,
);
wp_update_post( $update_post_args );


The above code leads to whitescreen / blank page, however the post is created in back end. But not updated as in above code.



When i change the 'post_status' to draft, It works. I think it may be a capability issue.



Below is code that is registering my post type:-



add_action('init', 'hg_rma_post_type');
function hg_rma_post_type()
{
$labels = array(
'name' => 'HG RMA',
'singular_name' => 'HG RMA',
'menu_name' => 'HG RMA',
'name_admin_bar' => 'HG RMA',
'add_new' => 'Add New',
'add_new_item' => 'Add New RMA',
'new_item' => 'New RMA',
'edit_item' => __('Edit RMA'),
'view_item' => __('View RMA'),
'all_items' => __('All RMA'),
'search_items' => __('Search RMA'),
'parent_item_colon' => __('Parent RMA:'),
'not_found' => __('No RMA found.'),
'not_found_in_trash' => __('No RMA found in Trash.')
);

$args = array(
'labels' => $labels,
'description' => __('Description.'),
'public' => false,
'publicly_queryable' => false,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array(
'slug' => 'hg-rma-panel'
),
'capability_type' => 'post',
'has_archive' => true,
'hierarchical' => false,
'menu_position' => 51,
'supports' => array(
'title',
'author'
),
'map_meta_cap' => true
);

register_post_type('hg-rma', $args);
}


I have other similar form exists on my website that interacts with other custom post types, but they are not creating such problems.



I will be really thankful, if anyone can help me out regarding this.










share|improve this question



























    1















    I am creating a custom post from a front end form.
    The post is successfully created but leading to white screen where the form is implemented.



    Here is my code:-



    $new_post_args = array(
    'post_title' => 'Lead is being updated',
    'post_status' => 'publish',
    'post_type' => 'hg-rma',
    'post_author' => 4470,
    );

    $post_id = wp_insert_post($new_post_args);
    if($post_id)
    {
    $update_post_args = array(
    'ID' => $post_id,
    'post_title' => $post_id,
    );
    wp_update_post( $update_post_args );


    The above code leads to whitescreen / blank page, however the post is created in back end. But not updated as in above code.



    When i change the 'post_status' to draft, It works. I think it may be a capability issue.



    Below is code that is registering my post type:-



    add_action('init', 'hg_rma_post_type');
    function hg_rma_post_type()
    {
    $labels = array(
    'name' => 'HG RMA',
    'singular_name' => 'HG RMA',
    'menu_name' => 'HG RMA',
    'name_admin_bar' => 'HG RMA',
    'add_new' => 'Add New',
    'add_new_item' => 'Add New RMA',
    'new_item' => 'New RMA',
    'edit_item' => __('Edit RMA'),
    'view_item' => __('View RMA'),
    'all_items' => __('All RMA'),
    'search_items' => __('Search RMA'),
    'parent_item_colon' => __('Parent RMA:'),
    'not_found' => __('No RMA found.'),
    'not_found_in_trash' => __('No RMA found in Trash.')
    );

    $args = array(
    'labels' => $labels,
    'description' => __('Description.'),
    'public' => false,
    'publicly_queryable' => false,
    'show_ui' => true,
    'show_in_menu' => true,
    'query_var' => true,
    'rewrite' => array(
    'slug' => 'hg-rma-panel'
    ),
    'capability_type' => 'post',
    'has_archive' => true,
    'hierarchical' => false,
    'menu_position' => 51,
    'supports' => array(
    'title',
    'author'
    ),
    'map_meta_cap' => true
    );

    register_post_type('hg-rma', $args);
    }


    I have other similar form exists on my website that interacts with other custom post types, but they are not creating such problems.



    I will be really thankful, if anyone can help me out regarding this.










    share|improve this question

























      1












      1








      1








      I am creating a custom post from a front end form.
      The post is successfully created but leading to white screen where the form is implemented.



      Here is my code:-



      $new_post_args = array(
      'post_title' => 'Lead is being updated',
      'post_status' => 'publish',
      'post_type' => 'hg-rma',
      'post_author' => 4470,
      );

      $post_id = wp_insert_post($new_post_args);
      if($post_id)
      {
      $update_post_args = array(
      'ID' => $post_id,
      'post_title' => $post_id,
      );
      wp_update_post( $update_post_args );


      The above code leads to whitescreen / blank page, however the post is created in back end. But not updated as in above code.



      When i change the 'post_status' to draft, It works. I think it may be a capability issue.



      Below is code that is registering my post type:-



      add_action('init', 'hg_rma_post_type');
      function hg_rma_post_type()
      {
      $labels = array(
      'name' => 'HG RMA',
      'singular_name' => 'HG RMA',
      'menu_name' => 'HG RMA',
      'name_admin_bar' => 'HG RMA',
      'add_new' => 'Add New',
      'add_new_item' => 'Add New RMA',
      'new_item' => 'New RMA',
      'edit_item' => __('Edit RMA'),
      'view_item' => __('View RMA'),
      'all_items' => __('All RMA'),
      'search_items' => __('Search RMA'),
      'parent_item_colon' => __('Parent RMA:'),
      'not_found' => __('No RMA found.'),
      'not_found_in_trash' => __('No RMA found in Trash.')
      );

      $args = array(
      'labels' => $labels,
      'description' => __('Description.'),
      'public' => false,
      'publicly_queryable' => false,
      'show_ui' => true,
      'show_in_menu' => true,
      'query_var' => true,
      'rewrite' => array(
      'slug' => 'hg-rma-panel'
      ),
      'capability_type' => 'post',
      'has_archive' => true,
      'hierarchical' => false,
      'menu_position' => 51,
      'supports' => array(
      'title',
      'author'
      ),
      'map_meta_cap' => true
      );

      register_post_type('hg-rma', $args);
      }


      I have other similar form exists on my website that interacts with other custom post types, but they are not creating such problems.



      I will be really thankful, if anyone can help me out regarding this.










      share|improve this question














      I am creating a custom post from a front end form.
      The post is successfully created but leading to white screen where the form is implemented.



      Here is my code:-



      $new_post_args = array(
      'post_title' => 'Lead is being updated',
      'post_status' => 'publish',
      'post_type' => 'hg-rma',
      'post_author' => 4470,
      );

      $post_id = wp_insert_post($new_post_args);
      if($post_id)
      {
      $update_post_args = array(
      'ID' => $post_id,
      'post_title' => $post_id,
      );
      wp_update_post( $update_post_args );


      The above code leads to whitescreen / blank page, however the post is created in back end. But not updated as in above code.



      When i change the 'post_status' to draft, It works. I think it may be a capability issue.



      Below is code that is registering my post type:-



      add_action('init', 'hg_rma_post_type');
      function hg_rma_post_type()
      {
      $labels = array(
      'name' => 'HG RMA',
      'singular_name' => 'HG RMA',
      'menu_name' => 'HG RMA',
      'name_admin_bar' => 'HG RMA',
      'add_new' => 'Add New',
      'add_new_item' => 'Add New RMA',
      'new_item' => 'New RMA',
      'edit_item' => __('Edit RMA'),
      'view_item' => __('View RMA'),
      'all_items' => __('All RMA'),
      'search_items' => __('Search RMA'),
      'parent_item_colon' => __('Parent RMA:'),
      'not_found' => __('No RMA found.'),
      'not_found_in_trash' => __('No RMA found in Trash.')
      );

      $args = array(
      'labels' => $labels,
      'description' => __('Description.'),
      'public' => false,
      'publicly_queryable' => false,
      'show_ui' => true,
      'show_in_menu' => true,
      'query_var' => true,
      'rewrite' => array(
      'slug' => 'hg-rma-panel'
      ),
      'capability_type' => 'post',
      'has_archive' => true,
      'hierarchical' => false,
      'menu_position' => 51,
      'supports' => array(
      'title',
      'author'
      ),
      'map_meta_cap' => true
      );

      register_post_type('hg-rma', $args);
      }


      I have other similar form exists on my website that interacts with other custom post types, but they are not creating such problems.



      I will be really thankful, if anyone can help me out regarding this.







      wordpress hook custom-wordpress-pages






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 21 '18 at 6:44









      Sharique AnwerSharique Anwer

      123




      123
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Found a workaround while R&D



          Set post_status to 'future' and set post_date to '1 minute later'.



          $current_date               = date('Y-m-d H:i:s');
          $post_date = date('Y-m-d H:i:s', strtotime('+1 minute',strtotime($current_date)));
          $new_post_args = array(
          'post_title' => 'Lead is being updated',
          'post_status' => 'future',
          'post_type' => $post_type,
          'post_author' => 4470,
          'post_date' => $post_date,
          );

          $post_id = wp_insert_post($new_post_args);





          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53406573%2fwp-insert-post-white-screen-blank-page%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Found a workaround while R&D



            Set post_status to 'future' and set post_date to '1 minute later'.



            $current_date               = date('Y-m-d H:i:s');
            $post_date = date('Y-m-d H:i:s', strtotime('+1 minute',strtotime($current_date)));
            $new_post_args = array(
            'post_title' => 'Lead is being updated',
            'post_status' => 'future',
            'post_type' => $post_type,
            'post_author' => 4470,
            'post_date' => $post_date,
            );

            $post_id = wp_insert_post($new_post_args);





            share|improve this answer




























              0














              Found a workaround while R&D



              Set post_status to 'future' and set post_date to '1 minute later'.



              $current_date               = date('Y-m-d H:i:s');
              $post_date = date('Y-m-d H:i:s', strtotime('+1 minute',strtotime($current_date)));
              $new_post_args = array(
              'post_title' => 'Lead is being updated',
              'post_status' => 'future',
              'post_type' => $post_type,
              'post_author' => 4470,
              'post_date' => $post_date,
              );

              $post_id = wp_insert_post($new_post_args);





              share|improve this answer


























                0












                0








                0







                Found a workaround while R&D



                Set post_status to 'future' and set post_date to '1 minute later'.



                $current_date               = date('Y-m-d H:i:s');
                $post_date = date('Y-m-d H:i:s', strtotime('+1 minute',strtotime($current_date)));
                $new_post_args = array(
                'post_title' => 'Lead is being updated',
                'post_status' => 'future',
                'post_type' => $post_type,
                'post_author' => 4470,
                'post_date' => $post_date,
                );

                $post_id = wp_insert_post($new_post_args);





                share|improve this answer













                Found a workaround while R&D



                Set post_status to 'future' and set post_date to '1 minute later'.



                $current_date               = date('Y-m-d H:i:s');
                $post_date = date('Y-m-d H:i:s', strtotime('+1 minute',strtotime($current_date)));
                $new_post_args = array(
                'post_title' => 'Lead is being updated',
                'post_status' => 'future',
                'post_type' => $post_type,
                'post_author' => 4470,
                'post_date' => $post_date,
                );

                $post_id = wp_insert_post($new_post_args);






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 21 '18 at 9:20









                Sharique AnwerSharique Anwer

                123




                123
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53406573%2fwp-insert-post-white-screen-blank-page%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    這個網誌中的熱門文章

                    Hercules Kyvelos

                    Tangent Lines Diagram Along Smooth Curve

                    Yusuf al-Mu'taman ibn Hud