• Hi – We are looking to take all ~900 of our WP blog posts and get just the article HTML – not the whole web page – into a new database table. Some of the articles rely on plugins that create tables or other stuff. I want to end up with a MySQL text field for each blog post consisting of the fully rendered HTML for each article. Any suggestions?

Viewing 1 replies (of 1 total)
  • Hello briandunning,

    if you got another wordpress installation for testing purposes you could try this

    <?php
    function posts_to_table (){
    	$ptt_query = new WP_Query( array( 'post_type' => 'any' ) ); // retrieves any type except revisions and types with 'exclude_from_search' set to TRUE
    	if ( $ptt_query->have_posts() ) {
    		while ( $ptt_query->have_posts() ) {
    			global $wpdb;
    			$wpdb->insert(
    				'htmlposts', //name of your new wordpress table
    				array(
    					'post_id'    	=> get_the_ID(),
    					'post_name'   	=> get_the_title(),
    					'post_content' 	=> get_the_content()
    				),
    				array( '%d', '%s', '%s' )
    			);
    			
    		}
    		wp_reset_postdata();
    	}
    }
    ?>

    Edit:
    I don’t know if it works but what you need is WP_Query and $wpdb->insert

    • This reply was modified 6 years, 4 months ago by Maurice.
Viewing 1 replies (of 1 total)
  • The topic ‘Export all posts as rendered HTML into a database table?’ is closed to new replies.