• 14-11-2023, 19:59:54
    #19
    A.AY adlı üyeden alıntı: mesajı görüntüle
    baktım id 1 2 3 şeklinde postlarda da çalışmadı
    https://test.selbermachendeko.com/hello-world/
    id 1 post

    https://test.selbermachendeko.com/page/28/
    ilk postlar
    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>";
        }
    
    }
    
    ?>
  • 15-11-2023, 11:35:11
    #20
    iskendercnr adlı üyeden alıntı: mesajı görüntüle
    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.