bir siteden veri çeken bot yazdım. siteden başlığı çekiyor title olarak atıyor resmi ve açıklamayı çekip birşeltiriyor ve içerik kısmına yazıyor
ve çekilen resmi de ortam kütüphanesine yüklüyor buraya kadar sıkıntı yok.
ben ortama yüklenen resmi thumbnail olmasını istiyorum yardımcı olabilirmisiniz.
<?php
if(isset($_POST["post_content"])){
// echo $_POST["post_content"];
/*
if($dwtbotpro_icerik["image"]){
$attachment_id = dwtbotpro_urlresimcek($dwtbotpro_icerik["image"]);
// print_r(wp_get_attachment_image($attachment_id,"full"));
// $dwtbotpro_icerik["image"] = wp_get_attachment_image($attachment_id,"full");
$yeniResim = wp_get_attachment_image_src($attachment_id,"full");
// print_r($yeniResim);
if(isset($yeniResim[0])){
$html = str_get_html($_POST["post_content"]);
$html->find("img",0)->src = $yeniResim[0];
$_POST["post_content"] = $html->outertext;
}
}
*/
$html = str_get_html($_POST["post_content"]);
if($resimler = $html->find("img")){
foreach($resimler AS $a=>$resim){
$resim->src = preg_replace('~"|\~usmi','',$resim->src);
// echo $resim->src;
$attachment_id = dwtbotpro_urlresimcek($resim->src);
$yeniResim = wp_get_attachment_image_src($attachment_id,"full");
if(isset($yeniResim[0])){
// $html = str_get_html($_POST["post_content"]);
$html->find("img",$a)->src = $yeniResim[0];
$_POST["post_content"] = $html->outertext;
}
}
}
if(!isset($_POST["post_category"])){
$_POST["post_category"] = array(1);
}
// Insert the post into the database
if($postup=wp_insert_post(array(
'post_title' => wp_strip_all_tags( $_POST['post_title'] ),
'post_content' => $_POST["post_content"],
'post_status' => 'publish',
'post_author' => 1,
// 'post_category' => array( 8,39 )
'post_category' => $_POST["post_category"]
))){
echo '<div class="dwtbotpro_durum dwtbotpro_basarili">Başarıyla eklendi </div>';
}else{
echo '<div class="dwtbotpro_durum dwtbotpro_basarisiz">Bir hata oluştu!</div>';
}
}
}else{
dwtbotpro_mansetler();
}
}
?>