Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8037329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:53:55+00:00 2026-06-05T02:53:55+00:00

I need to export all posts from certain category (that contains thousands posts) to

  • 0

I need to export all posts from certain category (that contains thousands posts) to a text document. And then someone will make corrections and changes in this document, and after this I have to enter all the updated posts to WP.
So I decided that the best way is to make a XML document (by this way it could be easy to enter the posts back).
So my code is:

require_once(dirname(__FILE__) . '/wp-blog-header.php');

$counter = 0;
$recorded = array();
$double=0;

$handle = fopen("all_posts.xml", "w");
fwrite($handle, "<all_posts>" . "\r\n"); // the root XML tag

// get all the categories from the global category  
$global_cat = get_categories(array("child_of"=>5, 'pad_counts'=>true, 'hierarchical' => 
false));

 foreach($global_cat as $child_cat){

global $post;
$args = array('numberposts' => 50000,'cat' => $child_cat->cat_ID);
print_r($child_cat); echo "<br>" . $counter ."<br>";
$q_posts = get_posts($args);
foreach($q_posts as $post){
    setup_postdata($post);

    if( in_array($post->ID, $recorded ) ) {continue;}
    $recorded[] = $post->ID;    

    $counter++;
    $title = get_the_title();
    $cur_categories = get_the_category();
    $cur_tags = get_the_tags();
    $d = get_the_date();
    $cont = get_the_content();

    fwrite($handle, "<post>" . "\r\n");

    fwrite($handle, "<title>" . $title . "</title>" . "\r\n");
    fwrite($handle, "<id>" . $post->ID . "</id>" . "\r\n");
    fwrite($handle, "<cur_cat>" . $child_cat->name . "</cur_cat>" . "\r\n");

    fwrite($handle, "<categories>\r\n");
        foreach ($cur_categories as $cat) {
            fwrite($handle, "<cat>" . $cat->cat_name . "</cat>");
        }               
    fwrite($handle, "\r\n</categories>" . "\r\n");

    fwrite($handle, "<tags>\r\n");
        foreach ($cur_tags as $tag) {
            fwrite($handle, "<tag>" . $tag->name . "</tag>");
        }               
    fwrite($handle, "\r\n</tags>" . "\r\n");
    fwrite($handle, "<date>" . $d . "</date>\r\n");

    fwrite($handle, "<content>\r\n" . $cont . "</content>\r\n\r\n");

    fwrite($handle, "</post>" . "\r\n");


}               

}
fwrite($handle, "</all_posts>");
fclose($handle);

The problem is, that because there is something like 10,000, the server does not give responce [I think it because that the xml file become to big or because of the excessively long time of procceng php script]. Only when I try to export posts from category that has only something like 2000 posts it works well.
What is the way to fix it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T02:53:56+00:00Added an answer on June 5, 2026 at 2:53 am

    On the top of your code set the max_execution_time to unlimited (or for some minutes) …

    ini_set('max_execution_time', 0);
    

    Try even to boost the memory limit used by PHP

    ini_set('memory_limit', '100M');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to export all of the objects from my MDB to text files
I need to export my gridview data to excel. No problems for this. All
I need to export an SQLite database from an Android phone to a computer.
I need to export a matrix of regression results from Stata to MATLAB. I
being in need to export a DOC file to TXT and then reimport it
I am completely new to VBA and need to export multiple graphs from an
I'm trying to export ALL records from a Visual Collection to excel. My code
I need to programmaticaly via a VBA/VBS script export all worksheets (4 in total
I have a SQL Server database, i need to export all of the data
I need to export a gridview to excel, I put the return html code

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.