Created
August 24, 2017 13:09
-
-
Save marcosnakamine/386a8e68d18892a1f9eee8aa7af18918 to your computer and use it in GitHub Desktop.
WordPress - Insert one post per image attachment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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