Skip to content

Instantly share code, notes, and snippets.

@2803media
Created November 8, 2012 08:46
Show Gist options
  • Save 2803media/4037615 to your computer and use it in GitHub Desktop.
Save 2803media/4037615 to your computer and use it in GitHub Desktop.
Wordpress featured image
$sql="SELECT * FROM wp_postmeta WHERE `meta_key` LIKE '_thumbnail_id'" ;
$result=mysql_query($sql) or die (mysql_error());
while ($var = mysql_fetch_array($result) ) {
$post_id = $var['post_id'];
$meta_id = $var['meta_id'];
print 'post_id : '.$post_id.'<p></p>';
$sql2="SELECT * FROM wp_posts WHERE `post_parent` = '$post_id' AND post_type = 'attachment' LIMIT 1" ;
 $result2=mysql_query($sql2) or die (mysql_error());
while ($var2 = mysql_fetch_array($result2) ) {
$ID = $var2['ID'];
print 'ID : '.$ID.'<p></p>';
$sql3="UPDATE wp_postmeta SET meta_value = '$ID' WHERE meta_id = '$meta_id' AND `meta_key` LIKE '_thumbnail_id'";
print ''.$sql3.'<p></p>';
mysql_query($sql3);
}
echo '<hr>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment