// Create post object $my_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 ) ); // Insert the post into the database wp_insert_post( $my_post );
Wordpress post ile içerik girme
1
●350
- 03-06-2016, 22:06:57Merhaba arkadaşlar php ile harici sayfadan içerik girmeyi kaynaklardan buldum ancak öne çıkartılmış görsel ve özel alana nasıl giriş yaptıracağım ? Şimdiden herkese yardımların ötürü teşekkür ederim.
- 04-06-2016, 21:30:15xPHPx adlı üyeden alıntı: mesajı görüntüle
Bu şekil çalışması gerekiyor ;
function imageDownload($link,$name=null,$uz=null){ $link_info = pathinfo($link); if(empty($uz)){ $uzanti = strtolower($link_info['extension']); }else{ $uzanti = $uz; } $file = ($name) ? $name.'.'.$uzanti : $link_info['basename']; $curl = curl_init($link); $timeout = 5; $fopen = fopen('../wp-content/uploads/'.$file,'w'); curl_setopt($curl, CURLOPT_HEADER,0); curl_setopt($curl, CURLOPT_RETURNTRANSFER,1); curl_setopt($curl, CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_0); curl_setopt($curl, CURLOPT_FILE, $fopen); curl_setopt ($curl, CURLOPT_CONNECTTIMEOUT, $timeout); curl_exec($curl); curl_close($curl); @fclose($fopen); } function urlTitleCreate($baslik = "") { $TR = array( 'ç','Ç','ı','İ','ş','Ş','ğ','Ğ','ö','Ö','ü','Ü','I' ); $EN = array( 'c','c','i','i','s','s','g','g','o','o','u','u','i' ); $baslik = str_replace($TR, $EN, $baslik); //$baslik = mb_strtolower($baslik, 'UTF-8'); $baslik = strtolower($baslik); $baslik = preg_replace('#[^-a-zA-Z0-9_ ]#', '', $baslik); $baslik = trim($baslik); $baslik = preg_replace('#[-_ ]+#', '-', $baslik); return $baslik; } function extensionSearch($isim) { $dizi = explode('.',$isim); $eleman = count($dizi) -1; $uzanti = $dizi["$eleman"]; return $uzanti; } // Create post object $my_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 ) ); // Insert the post into the database $post_id = wp_insert_post( $my_post ); $imageUrl = "https://www.r10.net/images/logom7.png"; $title = $_POST['post_title']; $imageNameChanged = urlTitleCreate(substr(md5($title))); $extension = extensionSearch($imageUrl); imageDownload($imageUrl,$imageNameChanged); $imageDirectory = get_bloginfo('url').'/wp-content/uploads/'; $serverImageUrl = $imageDirectory.$imageNameChanged.'.'.$extension; $attachment = array( 'guid' => $serverImageUrl, 'post_mime_type' => 'image/jpeg', 'post_title' => $title, 'post_content' => $title, 'post_type' => 'attachment', 'post_parent' => $post_id ); $attach_id = wp_insert_attachment($attachment, $serverImageUrl, $post_id); wp_update_attachment_metadata($attach_id, $attach_data); add_post_meta($post_id, '_thumbnail_id', $attach_id, true);