How to populate Wordpress Posts using wp_insert_post and SQL query










1















I am working on a project where I would like to programmatically create wordpress posts using an SQL query from an external database. I have been able to populate HighCharts graphs and display data in a tabular format querying the SQL databases with PHP. However, I can not figure out how to use wp_insert_post in the same way. I am also unsure where I should put this code. Any help is much appreciated! Here is my PHP.



<?php
/**
* Plugin Name: Post Creator

* Description: Matt's Post Creator
* Version: 0.2
* Author: Matt
* Author URI:
* License: GPLv2
*/

/**
* Enable PHP in Widgets
*/

$conzz = mysql_connect("localhost","database","databasepassword");





if (!$conzz)


die('Could not connect: ' . mysql_error());








mysql_select_db("chiensi_testing", $conzz);




$resultzz = mysql_query("SELECT T1.ID, REBATE_CODE, LONG_DESC, INCENT_TECH_ID, UPGRADE_TECH FROM T_L_INCENTIVES T1 INNER JOIN T_L_INCENT_TECH T2 ON T1.L_INCENT_TECH = T2.ID INNER JOIN T_LIGHTING_TYPE T3 ON T2.E_LIGHTING_TYPE_ID = T3.ID");



while($row = mysql_fetch_array($resultzz))


global $user_ID;
$new_post = array(
'post_title' => $row['REBATE_CODE'] ,
'post_content' => $row['LONG_DESC'] ,
'post_status' => 'publish',
'post_date' => date('Y-m-d H:i:s'),
'post_author' => $user_ID,
'post_type' => 'post',
'post_category' => array(10)
);
$posts_array=$new_post;



mysqli_close($conzz);

foreach ( $posts_array as $post )

$post_id = wp_insert_post($post);
;


?>









share|improve this question




























    1















    I am working on a project where I would like to programmatically create wordpress posts using an SQL query from an external database. I have been able to populate HighCharts graphs and display data in a tabular format querying the SQL databases with PHP. However, I can not figure out how to use wp_insert_post in the same way. I am also unsure where I should put this code. Any help is much appreciated! Here is my PHP.



    <?php
    /**
    * Plugin Name: Post Creator

    * Description: Matt's Post Creator
    * Version: 0.2
    * Author: Matt
    * Author URI:
    * License: GPLv2
    */

    /**
    * Enable PHP in Widgets
    */

    $conzz = mysql_connect("localhost","database","databasepassword");





    if (!$conzz)


    die('Could not connect: ' . mysql_error());








    mysql_select_db("chiensi_testing", $conzz);




    $resultzz = mysql_query("SELECT T1.ID, REBATE_CODE, LONG_DESC, INCENT_TECH_ID, UPGRADE_TECH FROM T_L_INCENTIVES T1 INNER JOIN T_L_INCENT_TECH T2 ON T1.L_INCENT_TECH = T2.ID INNER JOIN T_LIGHTING_TYPE T3 ON T2.E_LIGHTING_TYPE_ID = T3.ID");



    while($row = mysql_fetch_array($resultzz))


    global $user_ID;
    $new_post = array(
    'post_title' => $row['REBATE_CODE'] ,
    'post_content' => $row['LONG_DESC'] ,
    'post_status' => 'publish',
    'post_date' => date('Y-m-d H:i:s'),
    'post_author' => $user_ID,
    'post_type' => 'post',
    'post_category' => array(10)
    );
    $posts_array=$new_post;



    mysqli_close($conzz);

    foreach ( $posts_array as $post )

    $post_id = wp_insert_post($post);
    ;


    ?>









    share|improve this question


























      1












      1








      1








      I am working on a project where I would like to programmatically create wordpress posts using an SQL query from an external database. I have been able to populate HighCharts graphs and display data in a tabular format querying the SQL databases with PHP. However, I can not figure out how to use wp_insert_post in the same way. I am also unsure where I should put this code. Any help is much appreciated! Here is my PHP.



      <?php
      /**
      * Plugin Name: Post Creator

      * Description: Matt's Post Creator
      * Version: 0.2
      * Author: Matt
      * Author URI:
      * License: GPLv2
      */

      /**
      * Enable PHP in Widgets
      */

      $conzz = mysql_connect("localhost","database","databasepassword");





      if (!$conzz)


      die('Could not connect: ' . mysql_error());








      mysql_select_db("chiensi_testing", $conzz);




      $resultzz = mysql_query("SELECT T1.ID, REBATE_CODE, LONG_DESC, INCENT_TECH_ID, UPGRADE_TECH FROM T_L_INCENTIVES T1 INNER JOIN T_L_INCENT_TECH T2 ON T1.L_INCENT_TECH = T2.ID INNER JOIN T_LIGHTING_TYPE T3 ON T2.E_LIGHTING_TYPE_ID = T3.ID");



      while($row = mysql_fetch_array($resultzz))


      global $user_ID;
      $new_post = array(
      'post_title' => $row['REBATE_CODE'] ,
      'post_content' => $row['LONG_DESC'] ,
      'post_status' => 'publish',
      'post_date' => date('Y-m-d H:i:s'),
      'post_author' => $user_ID,
      'post_type' => 'post',
      'post_category' => array(10)
      );
      $posts_array=$new_post;



      mysqli_close($conzz);

      foreach ( $posts_array as $post )

      $post_id = wp_insert_post($post);
      ;


      ?>









      share|improve this question
















      I am working on a project where I would like to programmatically create wordpress posts using an SQL query from an external database. I have been able to populate HighCharts graphs and display data in a tabular format querying the SQL databases with PHP. However, I can not figure out how to use wp_insert_post in the same way. I am also unsure where I should put this code. Any help is much appreciated! Here is my PHP.



      <?php
      /**
      * Plugin Name: Post Creator

      * Description: Matt's Post Creator
      * Version: 0.2
      * Author: Matt
      * Author URI:
      * License: GPLv2
      */

      /**
      * Enable PHP in Widgets
      */

      $conzz = mysql_connect("localhost","database","databasepassword");





      if (!$conzz)


      die('Could not connect: ' . mysql_error());








      mysql_select_db("chiensi_testing", $conzz);




      $resultzz = mysql_query("SELECT T1.ID, REBATE_CODE, LONG_DESC, INCENT_TECH_ID, UPGRADE_TECH FROM T_L_INCENTIVES T1 INNER JOIN T_L_INCENT_TECH T2 ON T1.L_INCENT_TECH = T2.ID INNER JOIN T_LIGHTING_TYPE T3 ON T2.E_LIGHTING_TYPE_ID = T3.ID");



      while($row = mysql_fetch_array($resultzz))


      global $user_ID;
      $new_post = array(
      'post_title' => $row['REBATE_CODE'] ,
      'post_content' => $row['LONG_DESC'] ,
      'post_status' => 'publish',
      'post_date' => date('Y-m-d H:i:s'),
      'post_author' => $user_ID,
      'post_type' => 'post',
      'post_category' => array(10)
      );
      $posts_array=$new_post;



      mysqli_close($conzz);

      foreach ( $posts_array as $post )

      $post_id = wp_insert_post($post);
      ;


      ?>






      php mysql sql wordpress






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Sep 14 '17 at 20:11







      Matt Shirk

















      asked May 12 '14 at 18:56









      Matt ShirkMatt Shirk

      135115




      135115






















          1 Answer
          1






          active

          oldest

          votes


















          1














          EDITED AFTER COMMENTS BELOW:



          Try killing your connection to the first database before attempting to call wp_insert_post



          $conzz = mysql_connect("localhost","database","databasepassword");
          if (!$conzz)
          die('Could not connect: ' . mysql_error());



          mysql_select_db("database_name", $conzz);

          $resultzz = mysql_query("SELECT T1.ID, REBATE_CODE, LONG_DESC, INCENT_TECH_ID, UPGRADE_TECH FROM T_L_INCENTIVES T1 INNER JOIN T_L_INCENT_TECH T2 ON T1.L_INCENT_TECH = T2.ID INNER JOIN T_LIGHTING_TYPE T3 ON T2.E_LIGHTING_TYPE_ID = T3.ID");

          $posts_array = array();

          while($row = mysql_fetch_array($resultzz))


          global $user_ID;
          $new_post = array(
          'post_title' => $row['REBATE_CODE'] ,
          'post_content' => $row['LONG_DESC'] ,
          'post_status' => 'publish',
          'post_date' => date('Y-m-d H:i:s'),
          'post_author' => $user_ID,
          'post_type' => 'post',
          'post_category' => array(10)
          );
          $posts_array=$new_post;



          mysqli_close($conzz);

          foreach ( $posts_array as $post )

          $post_id = wp_insert_post($post);
          ;



          ?>





          share|improve this answer

























          • Hello, thanks for your help! The reason I am setting up the connection to the database is because it is an external database that is separate from the Wordpress Database. I need to pull values from this separate database and create WP posts with the results.

            – Matt Shirk
            May 12 '14 at 19:09











          • Then you would need to use the the sql connection as you have shown, store the returned values as an array, and then call wp_insert_post using those returned values as parameters

            – Talk nerdy to me
            May 12 '14 at 19:11











          • @Matt Shirk Are you getting any errors back from your code?

            – Talk nerdy to me
            May 12 '14 at 19:20












          • Hi - I am not receiving any errors now, but no posts are created either. I tried adding my code as a plugin, but when I try to "activate" it, nothing happens. I tried adding my code to "functions.php", but then I was kicked out of the Admin Dashboard and was unable to log back in until I removed the code from "functions.php" manually. I think that the problem may lie with adding the array items to the wp_insert_post function. Am I doing this correctly? Thanks again for your help!

            – Matt Shirk
            May 12 '14 at 19:28











          • Can you check the array that your building in the while loop? Instead of calling wp_insert_post var_dump( $new_post); Also, you shouldn't be getting locked out of admin for adding this to your functions.php, whatevers causing that could be the source of all your troubles. Is it the white screen of death?

            – Talk nerdy to me
            May 12 '14 at 19:59










          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%2f23616725%2fhow-to-populate-wordpress-posts-using-wp-insert-post-and-sql-query%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









          1














          EDITED AFTER COMMENTS BELOW:



          Try killing your connection to the first database before attempting to call wp_insert_post



          $conzz = mysql_connect("localhost","database","databasepassword");
          if (!$conzz)
          die('Could not connect: ' . mysql_error());



          mysql_select_db("database_name", $conzz);

          $resultzz = mysql_query("SELECT T1.ID, REBATE_CODE, LONG_DESC, INCENT_TECH_ID, UPGRADE_TECH FROM T_L_INCENTIVES T1 INNER JOIN T_L_INCENT_TECH T2 ON T1.L_INCENT_TECH = T2.ID INNER JOIN T_LIGHTING_TYPE T3 ON T2.E_LIGHTING_TYPE_ID = T3.ID");

          $posts_array = array();

          while($row = mysql_fetch_array($resultzz))


          global $user_ID;
          $new_post = array(
          'post_title' => $row['REBATE_CODE'] ,
          'post_content' => $row['LONG_DESC'] ,
          'post_status' => 'publish',
          'post_date' => date('Y-m-d H:i:s'),
          'post_author' => $user_ID,
          'post_type' => 'post',
          'post_category' => array(10)
          );
          $posts_array=$new_post;



          mysqli_close($conzz);

          foreach ( $posts_array as $post )

          $post_id = wp_insert_post($post);
          ;



          ?>





          share|improve this answer

























          • Hello, thanks for your help! The reason I am setting up the connection to the database is because it is an external database that is separate from the Wordpress Database. I need to pull values from this separate database and create WP posts with the results.

            – Matt Shirk
            May 12 '14 at 19:09











          • Then you would need to use the the sql connection as you have shown, store the returned values as an array, and then call wp_insert_post using those returned values as parameters

            – Talk nerdy to me
            May 12 '14 at 19:11











          • @Matt Shirk Are you getting any errors back from your code?

            – Talk nerdy to me
            May 12 '14 at 19:20












          • Hi - I am not receiving any errors now, but no posts are created either. I tried adding my code as a plugin, but when I try to "activate" it, nothing happens. I tried adding my code to "functions.php", but then I was kicked out of the Admin Dashboard and was unable to log back in until I removed the code from "functions.php" manually. I think that the problem may lie with adding the array items to the wp_insert_post function. Am I doing this correctly? Thanks again for your help!

            – Matt Shirk
            May 12 '14 at 19:28











          • Can you check the array that your building in the while loop? Instead of calling wp_insert_post var_dump( $new_post); Also, you shouldn't be getting locked out of admin for adding this to your functions.php, whatevers causing that could be the source of all your troubles. Is it the white screen of death?

            – Talk nerdy to me
            May 12 '14 at 19:59















          1














          EDITED AFTER COMMENTS BELOW:



          Try killing your connection to the first database before attempting to call wp_insert_post



          $conzz = mysql_connect("localhost","database","databasepassword");
          if (!$conzz)
          die('Could not connect: ' . mysql_error());



          mysql_select_db("database_name", $conzz);

          $resultzz = mysql_query("SELECT T1.ID, REBATE_CODE, LONG_DESC, INCENT_TECH_ID, UPGRADE_TECH FROM T_L_INCENTIVES T1 INNER JOIN T_L_INCENT_TECH T2 ON T1.L_INCENT_TECH = T2.ID INNER JOIN T_LIGHTING_TYPE T3 ON T2.E_LIGHTING_TYPE_ID = T3.ID");

          $posts_array = array();

          while($row = mysql_fetch_array($resultzz))


          global $user_ID;
          $new_post = array(
          'post_title' => $row['REBATE_CODE'] ,
          'post_content' => $row['LONG_DESC'] ,
          'post_status' => 'publish',
          'post_date' => date('Y-m-d H:i:s'),
          'post_author' => $user_ID,
          'post_type' => 'post',
          'post_category' => array(10)
          );
          $posts_array=$new_post;



          mysqli_close($conzz);

          foreach ( $posts_array as $post )

          $post_id = wp_insert_post($post);
          ;



          ?>





          share|improve this answer

























          • Hello, thanks for your help! The reason I am setting up the connection to the database is because it is an external database that is separate from the Wordpress Database. I need to pull values from this separate database and create WP posts with the results.

            – Matt Shirk
            May 12 '14 at 19:09











          • Then you would need to use the the sql connection as you have shown, store the returned values as an array, and then call wp_insert_post using those returned values as parameters

            – Talk nerdy to me
            May 12 '14 at 19:11











          • @Matt Shirk Are you getting any errors back from your code?

            – Talk nerdy to me
            May 12 '14 at 19:20












          • Hi - I am not receiving any errors now, but no posts are created either. I tried adding my code as a plugin, but when I try to "activate" it, nothing happens. I tried adding my code to "functions.php", but then I was kicked out of the Admin Dashboard and was unable to log back in until I removed the code from "functions.php" manually. I think that the problem may lie with adding the array items to the wp_insert_post function. Am I doing this correctly? Thanks again for your help!

            – Matt Shirk
            May 12 '14 at 19:28











          • Can you check the array that your building in the while loop? Instead of calling wp_insert_post var_dump( $new_post); Also, you shouldn't be getting locked out of admin for adding this to your functions.php, whatevers causing that could be the source of all your troubles. Is it the white screen of death?

            – Talk nerdy to me
            May 12 '14 at 19:59













          1












          1








          1







          EDITED AFTER COMMENTS BELOW:



          Try killing your connection to the first database before attempting to call wp_insert_post



          $conzz = mysql_connect("localhost","database","databasepassword");
          if (!$conzz)
          die('Could not connect: ' . mysql_error());



          mysql_select_db("database_name", $conzz);

          $resultzz = mysql_query("SELECT T1.ID, REBATE_CODE, LONG_DESC, INCENT_TECH_ID, UPGRADE_TECH FROM T_L_INCENTIVES T1 INNER JOIN T_L_INCENT_TECH T2 ON T1.L_INCENT_TECH = T2.ID INNER JOIN T_LIGHTING_TYPE T3 ON T2.E_LIGHTING_TYPE_ID = T3.ID");

          $posts_array = array();

          while($row = mysql_fetch_array($resultzz))


          global $user_ID;
          $new_post = array(
          'post_title' => $row['REBATE_CODE'] ,
          'post_content' => $row['LONG_DESC'] ,
          'post_status' => 'publish',
          'post_date' => date('Y-m-d H:i:s'),
          'post_author' => $user_ID,
          'post_type' => 'post',
          'post_category' => array(10)
          );
          $posts_array=$new_post;



          mysqli_close($conzz);

          foreach ( $posts_array as $post )

          $post_id = wp_insert_post($post);
          ;



          ?>





          share|improve this answer















          EDITED AFTER COMMENTS BELOW:



          Try killing your connection to the first database before attempting to call wp_insert_post



          $conzz = mysql_connect("localhost","database","databasepassword");
          if (!$conzz)
          die('Could not connect: ' . mysql_error());



          mysql_select_db("database_name", $conzz);

          $resultzz = mysql_query("SELECT T1.ID, REBATE_CODE, LONG_DESC, INCENT_TECH_ID, UPGRADE_TECH FROM T_L_INCENTIVES T1 INNER JOIN T_L_INCENT_TECH T2 ON T1.L_INCENT_TECH = T2.ID INNER JOIN T_LIGHTING_TYPE T3 ON T2.E_LIGHTING_TYPE_ID = T3.ID");

          $posts_array = array();

          while($row = mysql_fetch_array($resultzz))


          global $user_ID;
          $new_post = array(
          'post_title' => $row['REBATE_CODE'] ,
          'post_content' => $row['LONG_DESC'] ,
          'post_status' => 'publish',
          'post_date' => date('Y-m-d H:i:s'),
          'post_author' => $user_ID,
          'post_type' => 'post',
          'post_category' => array(10)
          );
          $posts_array=$new_post;



          mysqli_close($conzz);

          foreach ( $posts_array as $post )

          $post_id = wp_insert_post($post);
          ;



          ?>






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited May 13 '14 at 2:09

























          answered May 12 '14 at 19:03









          Talk nerdy to meTalk nerdy to me

          840710




          840710












          • Hello, thanks for your help! The reason I am setting up the connection to the database is because it is an external database that is separate from the Wordpress Database. I need to pull values from this separate database and create WP posts with the results.

            – Matt Shirk
            May 12 '14 at 19:09











          • Then you would need to use the the sql connection as you have shown, store the returned values as an array, and then call wp_insert_post using those returned values as parameters

            – Talk nerdy to me
            May 12 '14 at 19:11











          • @Matt Shirk Are you getting any errors back from your code?

            – Talk nerdy to me
            May 12 '14 at 19:20












          • Hi - I am not receiving any errors now, but no posts are created either. I tried adding my code as a plugin, but when I try to "activate" it, nothing happens. I tried adding my code to "functions.php", but then I was kicked out of the Admin Dashboard and was unable to log back in until I removed the code from "functions.php" manually. I think that the problem may lie with adding the array items to the wp_insert_post function. Am I doing this correctly? Thanks again for your help!

            – Matt Shirk
            May 12 '14 at 19:28











          • Can you check the array that your building in the while loop? Instead of calling wp_insert_post var_dump( $new_post); Also, you shouldn't be getting locked out of admin for adding this to your functions.php, whatevers causing that could be the source of all your troubles. Is it the white screen of death?

            – Talk nerdy to me
            May 12 '14 at 19:59

















          • Hello, thanks for your help! The reason I am setting up the connection to the database is because it is an external database that is separate from the Wordpress Database. I need to pull values from this separate database and create WP posts with the results.

            – Matt Shirk
            May 12 '14 at 19:09











          • Then you would need to use the the sql connection as you have shown, store the returned values as an array, and then call wp_insert_post using those returned values as parameters

            – Talk nerdy to me
            May 12 '14 at 19:11











          • @Matt Shirk Are you getting any errors back from your code?

            – Talk nerdy to me
            May 12 '14 at 19:20












          • Hi - I am not receiving any errors now, but no posts are created either. I tried adding my code as a plugin, but when I try to "activate" it, nothing happens. I tried adding my code to "functions.php", but then I was kicked out of the Admin Dashboard and was unable to log back in until I removed the code from "functions.php" manually. I think that the problem may lie with adding the array items to the wp_insert_post function. Am I doing this correctly? Thanks again for your help!

            – Matt Shirk
            May 12 '14 at 19:28











          • Can you check the array that your building in the while loop? Instead of calling wp_insert_post var_dump( $new_post); Also, you shouldn't be getting locked out of admin for adding this to your functions.php, whatevers causing that could be the source of all your troubles. Is it the white screen of death?

            – Talk nerdy to me
            May 12 '14 at 19:59
















          Hello, thanks for your help! The reason I am setting up the connection to the database is because it is an external database that is separate from the Wordpress Database. I need to pull values from this separate database and create WP posts with the results.

          – Matt Shirk
          May 12 '14 at 19:09





          Hello, thanks for your help! The reason I am setting up the connection to the database is because it is an external database that is separate from the Wordpress Database. I need to pull values from this separate database and create WP posts with the results.

          – Matt Shirk
          May 12 '14 at 19:09













          Then you would need to use the the sql connection as you have shown, store the returned values as an array, and then call wp_insert_post using those returned values as parameters

          – Talk nerdy to me
          May 12 '14 at 19:11





          Then you would need to use the the sql connection as you have shown, store the returned values as an array, and then call wp_insert_post using those returned values as parameters

          – Talk nerdy to me
          May 12 '14 at 19:11













          @Matt Shirk Are you getting any errors back from your code?

          – Talk nerdy to me
          May 12 '14 at 19:20






          @Matt Shirk Are you getting any errors back from your code?

          – Talk nerdy to me
          May 12 '14 at 19:20














          Hi - I am not receiving any errors now, but no posts are created either. I tried adding my code as a plugin, but when I try to "activate" it, nothing happens. I tried adding my code to "functions.php", but then I was kicked out of the Admin Dashboard and was unable to log back in until I removed the code from "functions.php" manually. I think that the problem may lie with adding the array items to the wp_insert_post function. Am I doing this correctly? Thanks again for your help!

          – Matt Shirk
          May 12 '14 at 19:28





          Hi - I am not receiving any errors now, but no posts are created either. I tried adding my code as a plugin, but when I try to "activate" it, nothing happens. I tried adding my code to "functions.php", but then I was kicked out of the Admin Dashboard and was unable to log back in until I removed the code from "functions.php" manually. I think that the problem may lie with adding the array items to the wp_insert_post function. Am I doing this correctly? Thanks again for your help!

          – Matt Shirk
          May 12 '14 at 19:28













          Can you check the array that your building in the while loop? Instead of calling wp_insert_post var_dump( $new_post); Also, you shouldn't be getting locked out of admin for adding this to your functions.php, whatevers causing that could be the source of all your troubles. Is it the white screen of death?

          – Talk nerdy to me
          May 12 '14 at 19:59





          Can you check the array that your building in the while loop? Instead of calling wp_insert_post var_dump( $new_post); Also, you shouldn't be getting locked out of admin for adding this to your functions.php, whatevers causing that could be the source of all your troubles. Is it the white screen of death?

          – Talk nerdy to me
          May 12 '14 at 19:59



















          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%2f23616725%2fhow-to-populate-wordpress-posts-using-wp-insert-post-and-sql-query%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







          這個網誌中的熱門文章

          How to read a connectionString WITH PROVIDER in .NET Core?

          Node.js Script on GitHub Pages or Amazon S3

          Museum of Modern and Contemporary Art of Trento and Rovereto