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 674263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T00:41:12+00:00 2026-05-14T00:41:12+00:00

If I want to keep an xml file updated with all the images that

  • 0

If I want to keep an xml file updated with all the images that a user has attched to a page, I shouldn’t write create and generate an xml-file everytime someone visits that page (because it would cause too much overhead) – should I create and fill the file when the user attaches new content to the page in the admin console instead?

  • 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-05-14T00:41:13+00:00Added an answer on May 14, 2026 at 12:41 am

    First, you will need to create directory under wp-content. Lets called it wp-content/xmlimages/
    Now, copy this code and paste it to wp-content/plugins/cr-attachmentpost2xml.php:

    <?php
    /*
    Plugin Name: CR Attachment Post To XML
    Plugin URI: http://bayu.freelancer.web.id/search/plugin
    Description: Automatically create XML files for each post that list post attachment of that particular post.
    Version: 0.1
    Author: Arief Bayu Purwanto
    Author URI: http://bayu.freelancer.web.id/
    
    */
    
    add_action('publish_post', 'cr_attachmentpost2xml_publish_post_hook');
    
    //add_action('admin_menu', 'cr_attachmentpost2xml_test');
    
    function cr_attachmentpost2xml_publish_post_hook( $post_id ){
        __cr_attachmentpost2xml_impl( $post_id );
        return $post_id;
    }
    
    function cr_attachmentpost2xml_test(){
        __cr_attachmentpost2xml_impl( 738 );
    }
    
    function __cr_attachmentpost2xml_impl( $post_id ){
        $udir = wp_upload_dir();
        $writepath = $udir['basedir'] . '/xmlimages/';
        $attachment = get_children( 'post_type=attachment&post_parent=' . $post_id);
    
        if(wp_is_post_revision($postId)) return $post_id;
        //print_r($attachment);
        $xml = "<?xml version=\"1.0\"?>";
        $xml .= "<attachments>";
    
        foreach($attachment as $att){
            $image_src = wp_get_attachment_image_src( $att->ID );
            $xml .= "<attachment>";
            $xml .= "<id>{$att->ID}</id>";
            $xml .= "<date>{$att->post_date}</date>";
            $xml .= "<title>{$att->post_title}</title>";
            $xml .= "<mime_type>{$att->post_mime_type}</mime_type>";
            $xml .= "<url>".$image_src[0]."</url>";
    
            $xml .= "</attachment>";
        }
        $xml .= "</attachments>";
        file_put_contents($writepath . $post_id . ".xml", $xml);
        //echo "$xml";
    }
    

    WARNING: Don’t except something special here, as it’s just a quick & dirty code. Hope it work the way to want and if you do use this code, don’t forget to check for any security hole it might introduce.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an XML file that I want to sort by an attribute. The
I have an application that read an online xml file, now i want to
I am processing an XML file where I want to keep count of the
I have an xml file where I store all usernames and passwords. I want
I want to keep my footer at the bottom of the page while keeping
I want to keep only numbers and remove all characters from a variable. For
I have a maven project that is generating a .war file. I want to
So I want to scan a large XML file (40mb) and as far as
I have an xml file and I want to display(render) it as it is
I want to read in an XML file and modify an element then save

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.