https://test.selbermachendeko.com/wp...=1&action=edit
panelden kontrol edin. kodlar çalışıyor bende
<?php
// r10.net/iskendercnr
require __DIR__ . '/wp-load.php';
$args = array(
'post_type' => 'post',
'posts_per_page' => -1,
);
$posts = get_posts($args);
foreach ($posts as $post) {
$post_id = $post->ID;
echo "Konu: " . $post->post_title;
$attachments = get_posts(array(
'post_type' => 'attachment',
'posts_per_page' => -1,
'post_parent' => $post_id,
));
if ($attachments) {
echo "<br>Resim ID: " . $attachments[0]->ID;
set_post_thumbnail($post_id, $attachments[0]->ID);
echo "<br>işlem tamam: " . $post_id . "<br>";
}
}
?>
İçerikteki resimler, içeriğe atanmamış olabilir. Yani post_parent boş olabilir. O yüzden extra regex yöntemi ile url leri alıp, o şekilde bir atama yapmak kodu daha da işlevsel yapabilir.