Skip to content

Instantly share code, notes, and snippets.

@marcosnakamine
Created August 24, 2017 13:09
Show Gist options
  • Save marcosnakamine/386a8e68d18892a1f9eee8aa7af18918 to your computer and use it in GitHub Desktop.
Save marcosnakamine/386a8e68d18892a1f9eee8aa7af18918 to your computer and use it in GitHub Desktop.
WordPress - Insert one post per image attachment
<?php
$posts = get_posts( array(
'post_type' => 'attachment',
'post_mime_type' => 'image',
'posts_per_page' => -1
) );
foreach ($posts as $key => $value) {
$post_id = wp_insert_post( array(
'post_type' => 'new_post_type'
) );
var_dump( set_post_thumbnail( $post_id, $value->ID ) );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment