Forums

Can I overwrite existing posts with Import tool? (3 posts)

  1. eliza_peterson
    Member
    Posted 8 months ago #

    I am curious if I can re-import the posts, comments, pages, etc to my existing website without error, without finding I have double posted all my content and without affecting my themes. I believe I need to fix a snippet of code in an .xml file and to do so, will need to re-import.

    I hope this makes sense -
    Thank you!
    my website - http://www.theinspiredclassroom.com

  2. Shiva Napoleon
    Member
    Posted 8 months ago #

    Hi,

    I had a solution for this in WP 2.8.4 time. Don't if that same would work for you. I had to edit the wp-admin/import/import.php file.

    I removed the if

    if ( $post_exists ) {
    			echo '<li>';
    			printf(__('Post <em>%s</em> already exists.'), stripslashes($post_title));
    			$comment_post_ID = $post_id = $post_exists;
    		} else {

    And then inserted the below code at the printf(__('Importing post....
    Also rememember to remove the closing tag for the first if statement (II one after wp_set_post_tags($post_id, $post_tags);

    // changed code here for if stmt
    if ( $post_exists ) {
    $ID = $post_ID;
    					$postdata = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'post_date', 'post_date_gmt', 'to_ping', 'post_name', 'post_password', 'post_parent', 'menu_order', 'post_author', 'tags_input', 'page_template');
    
    					$comment_post_ID = $post_id = wp_update_post($postdata);
    					printf(__(' and updated'));
    				} else {
    					$comment_post_ID = $post_id = wp_insert_post($postdata);
    					printf(__(' and created new Post/Page'));
    				}
    
    			}

    Let me know if you need more help.

  3. Shiva Napoleon
    Member
    Posted 8 months ago #

    Sorry, my previous post did not include details:
    In my situation, I exported the posts as xml, edited content in all the posts and used wordpress import tool to re-import them.
    I changed the code so that it will re-write existing posts and not skip them.

    If your case if you are just re-importing, with the exact contents, category, comments, etc, you don't have to make changes to the code. Just import using WP tool, it will skip the existing ones (posts with the exact same title are considered existing) and import only the new ones.

Reply

You must log in to post.

About this Topic

Tags