Title: require(&#039;wp-blog-header.php&#039;) does not work in a loop
Last modified: August 20, 2016

---

# require('wp-blog-header.php') does not work in a loop

 *  Resolved [hinhthoi](https://wordpress.org/support/users/hinhthoi/)
 * (@hinhthoi)
 * [14 years ago](https://wordpress.org/support/topic/requirewp-blog-headerphp-does-not-work-in-a-loop/)
 * Hi,
    I’m trying to use wp_insert_post from an external php file. This file works
   fine if there is no loop
 *     ```
       <?php
       require('wp-blog-header.php');
       $tmpstr = array(
                     'ID' => 1,
                     'post_title' => $title,
                     'post_content' => $post content,
                     'post_status' => 'publish',
                     'post_author' => '1',
                     'post_type' => $type
                  );
       wp_insert_post($tmpstr);
       ?>
       ```
   
 * However, when i put a loop,
    `<?php for ($i=0;$i<10,$i++) { require(‘wp-blog-
   header.php’); $tmpstr = array( ‘ID’ => 1, ‘post_title’ => $title[$i], ‘post_content’
   => $post content[$i], ‘post_status’ => ‘publish’, ‘post_author’ => ‘1’, ‘post_type’
   => $type ); wp_insert_post($tmpstr); } ?> It insert only 1 time into mysql database,
   then it stops Could anyone please help me to make it loop for 10 times, so that
   it can insert 10 entries? Thank you in advance!

Viewing 6 replies - 1 through 6 (of 6 total)

 *  [Frumph](https://wordpress.org/support/users/frumph/)
 * (@frumph)
 * [14 years ago](https://wordpress.org/support/topic/requirewp-blog-headerphp-does-not-work-in-a-loop/#post-2771066)
 * try:
 * `require(ABSPATH.'wp-blog-header.php');`
 * wp_insert_post might be changing the relative url to the wp-admin directory
 *  Thread Starter [hinhthoi](https://wordpress.org/support/users/hinhthoi/)
 * (@hinhthoi)
 * [14 years ago](https://wordpress.org/support/topic/requirewp-blog-headerphp-does-not-work-in-a-loop/#post-2771085)
 * Hi Frumph
    Thank you for your help. But can you elaborate more about this? The
   path to the wp-blog-header.php is /home/myusername/public_html, so should it 
   be require(‘/home/myusername/public_html/wp-blog-header.php’); ?
 * I have tested that but it still insert only one entry
 *  [Frumph](https://wordpress.org/support/users/frumph/)
 * (@frumph)
 * [14 years ago](https://wordpress.org/support/topic/requirewp-blog-headerphp-does-not-work-in-a-loop/#post-2771119)
 * was just a thought, otherwise it could be ‘exiting’ out of the function/loop 
   with an error, have you checked your php error logs?
 *  Thread Starter [hinhthoi](https://wordpress.org/support/users/hinhthoi/)
 * (@hinhthoi)
 * [14 years ago](https://wordpress.org/support/topic/requirewp-blog-headerphp-does-not-work-in-a-loop/#post-2771250)
 * Hi, could you tell me how to check the php logs? Since i’m new to php stuffs.
   It seems like this information is not accessible from a shared server, is it?
 *  [Frumph](https://wordpress.org/support/users/frumph/)
 * (@frumph)
 * [14 years ago](https://wordpress.org/support/topic/requirewp-blog-headerphp-does-not-work-in-a-loop/#post-2771257)
 * That you will have to ask your hosting about.
 * Mine on Cirtex hosting is in a file called error_log .. other peoples are in 
   a /logs directory. It all depends on your hostings setup to handle error logs.
 *  Thread Starter [hinhthoi](https://wordpress.org/support/users/hinhthoi/)
 * (@hinhthoi)
 * [14 years ago](https://wordpress.org/support/topic/requirewp-blog-headerphp-does-not-work-in-a-loop/#post-2771260)
 * Hi Frumph, thanks for your help. I have resolve the problem by putting the require
   command outside of the loop

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘require('wp-blog-header.php') does not work in a loop’ is closed to new
replies.

## Tags

 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [MySQL](https://wordpress.org/support/topic-tag/mysql/)
 * [wp_insert_post](https://wordpress.org/support/topic-tag/wp_insert_post/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 6 replies
 * 2 participants
 * Last reply from: [hinhthoi](https://wordpress.org/support/users/hinhthoi/)
 * Last activity: [14 years ago](https://wordpress.org/support/topic/requirewp-blog-headerphp-does-not-work-in-a-loop/#post-2771260)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
