• 25-07-2014, 01:31:34
    #1
    Üyeliği durduruldu
    Merhaba arkadaşalr,

    Bir bot yapıyorum bot otomatik olarak wp ye konu açıyor.

    	$ekle= mysql_query("INSERT INTO wp_posts SET post_title='$desgisken' ") or die (mysql_Error());
    gibisinden verilerimi giriyor fakat özel alanları nasıl eklerim? artı olarak öne çıkan görsele nasıl url verebilirim bu şekilde?
  • 25-07-2014, 09:51:07
    #2
    Özel alanları şu şekilde ekleyebilirsin;

    INSERT INTO 'wp_postmeta' ('post_id', 'meta_key', 'meta_value') VALUES (mysql_insert_id(), 'ozel_alan_adi', 'özel alan değeri');
    Öne çıkarılmış görsellerde wp_posts tablosuna post tipi attachment olarak kayıt ekleniyor ve postmeta tablosunada bir kayıt ekliyor şöyle;

    INSERT INTO `wp_postmeta` (`post_id`, `meta_key`, `meta_value`) VALUES (1, '_thumbnail_id', '5');
    Bu şekilde uğraşmak yerine direk olarak wp_insert_post fonksiyonunu kullanabilirsin. Özel alan ve öne çıkarılmış görsel ekleyen bir örnek;

    /**
     * Post dizisi, buraya bir çok özellik gelebilir tamamını codex sayfasından görebilirsin
     */
    $post_data = array(
        'post_title'   => 'Başlık',
        'post_content' => 'İçerik',
        'post_status'  => 'publish',
        'post_author'  => 1
    );
    
    $post_id = wp_insert_post( $post_data ); //$post_id eklediğimiz yaznının ID'si şimdi buna özel alan vs. ekleyebiliriz
    
    /**
     * Post'umuza özel alan ekledik
     */
    add_post_meta($post_id, 'ozel_alan_adi', 'Özel alan değeri', true);
    
    /**
     * $image_url uzaktaki resmin url si olmalı
     */
    $image_url = 'https://www.r10.net/images/logom7.png';
    
    /**
     * Öne çıkarılmış görseli ekliyeceğiz
     */
    $upload_dir = wp_upload_dir();
    $image_data = file_get_contents($image_url);
    $filename = basename($image_url);
    if(wp_mkdir_p($upload_dir['path']))
        $file = $upload_dir['path'] . '/' . $filename;
    else
        $file = $upload_dir['basedir'] . '/' . $filename;
    file_put_contents($file, $image_data);
    
    $wp_filetype = wp_check_filetype($filename, null );
    $attachment = array(
        'post_mime_type' => $wp_filetype['type'],
        'post_title' => sanitize_file_name($filename),
        'post_content' => '',
        'post_status' => 'inherit'
    );
    $attach_id = wp_insert_attachment( $attachment, $file, $post_id );
    require_once(ABSPATH . 'wp-admin/includes/image.php');
    $attach_data = wp_generate_attachment_metadata( $attach_id, $file );
    wp_update_attachment_metadata( $attach_id, $attach_data );
    
    set_post_thumbnail( $post_id, $attach_id );

    Eğer uzaktan eklemek istiyorsanda; bir dosya oluştur wp sitede post edilen değerlerden eklet içeriği. $_get ile özel bir şifre koy gelen parametre ona eşit değilse işlem yaptırma.
  • 25-07-2014, 10:07:50
    #3
    Üyeliği durduruldu
    jebias adlı üyeden alıntı: mesajı görüntüle
    Özel alanları şu şekilde ekleyebilirsin;

    INSERT INTO 'wp_postmeta' ('post_id', 'meta_key', 'meta_value') VALUES (mysql_insert_id(), 'ozel_alan_adi', 'özel alan değeri');
    Öne çıkarılmış görsellerde wp_posts tablosuna post tipi attachment olarak kayıt ekleniyor ve postmeta tablosunada bir kayıt ekliyor şöyle;

    INSERT INTO `wp_postmeta` (`post_id`, `meta_key`, `meta_value`) VALUES (1, '_thumbnail_id', '5');
    Bu şekilde uğraşmak yerine direk olarak wp_insert_post fonksiyonunu kullanabilirsin. Özel alan ve öne çıkarılmış görsel ekleyen bir örnek;

    /**
     * Post dizisi, buraya bir çok özellik gelebilir tamamını codex sayfasından görebilirsin
     */
    $post_data = array(
        'post_title'   => 'Başlık',
        'post_content' => 'İçerik',
        'post_status'  => 'publish',
        'post_author'  => 1
    );
    
    $post_id = wp_insert_post( $post_data ); //$post_id eklediğimiz yaznının ID'si şimdi buna özel alan vs. ekleyebiliriz
    
    /**
     * Post'umuza özel alan ekledik
     */
    add_post_meta($post_id, 'ozel_alan_adi', 'Özel alan değeri', true);
    
    /**
     * $image_url uzaktaki resmin url si olmalı
     */
    $image_url = 'https://www.r10.net/images/logom7.png';
    
    /**
     * Öne çıkarılmış görseli ekliyeceğiz
     */
    $upload_dir = wp_upload_dir();
    $image_data = file_get_contents($image_url);
    $filename = basename($image_url);
    if(wp_mkdir_p($upload_dir['path']))
        $file = $upload_dir['path'] . '/' . $filename;
    else
        $file = $upload_dir['basedir'] . '/' . $filename;
    file_put_contents($file, $image_data);
    
    $wp_filetype = wp_check_filetype($filename, null );
    $attachment = array(
        'post_mime_type' => $wp_filetype['type'],
        'post_title' => sanitize_file_name($filename),
        'post_content' => '',
        'post_status' => 'inherit'
    );
    $attach_id = wp_insert_attachment( $attachment, $file, $post_id );
    require_once(ABSPATH . 'wp-admin/includes/image.php');
    $attach_data = wp_generate_attachment_metadata( $attach_id, $file );
    wp_update_attachment_metadata( $attach_id, $attach_data );
    
    set_post_thumbnail( $post_id, $attach_id );

    Eğer uzaktan eklemek istiyorsanda; bir dosya oluştur wp sitede post edilen değerlerden eklet içeriği. $_get ile özel bir şifre koy gelen parametre ona eşit değilse işlem yaptırma.

    Öncelik ile çok teşekkürler. Bu verdiğin php kodu ile uzaktan dosya ekleyemezmiyim?
  • 25-07-2014, 10:14:29
    #4
    Şöyle yaparsan olur büyük ihtimalle hocam;

    <?php
    
    if(!$_POST || $_GET['sifre'] != 'benim_ozel_sifrem') 
    	die();
    
    /**
     * Post dizisi, buraya bir çok özellik gelebilir tamamını codex sayfasından görebilirsin
     */
    $post_data = array();
    
    foreach ($_POST as $key => $value) {
          if($key != 'resim_url')
    	$post_data[$key] = $value;
    }
    
    $post_id = wp_insert_post( $post_data ); //$post_id eklediğimiz yaznının ID'si şimdi buna özel alan vs. ekleyebiliriz
    
    /**
     * Post'umuza özel alan ekledik
     */
    add_post_meta($post_id, 'ozel_alan_adi', 'Özel alan değeri', true);
    
    /**
     * $image_url uzaktaki resmin url si olmalı
     */
    $image_url = $_POST['resim_url'];
    
    /**
     * Öne çıkarılmış görseli ekliyeceğiz
     */
    $upload_dir = wp_upload_dir();
    $image_data = file_get_contents($image_url);
    $filename = basename($image_url);
    if(wp_mkdir_p($upload_dir['path']))
        $file = $upload_dir['path'] . '/' . $filename;
    else
        $file = $upload_dir['basedir'] . '/' . $filename;
    file_put_contents($file, $image_data);
    
    $wp_filetype = wp_check_filetype($filename, null );
    $attachment = array(
        'post_mime_type' => $wp_filetype['type'],
        'post_title' => sanitize_file_name($filename),
        'post_content' => '',
        'post_status' => 'inherit'
    );
    $attach_id = wp_insert_attachment( $attachment, $file, $post_id );
    require_once(ABSPATH . 'wp-admin/includes/image.php');
    $attach_data = wp_generate_attachment_metadata( $attach_id, $file );
    wp_update_attachment_metadata( $attach_id, $attach_data );
    
    set_post_thumbnail( $post_id, $attach_id );
    Bu dosyayı WP sitene at, daha sonra uzaktan ekletmek için cURL ile data post edicez onuda şöyle;

    $ch = curl_init();
    
    curl_setopt($ch, CURLOPT_URL,"http://wpsiten.com/wp-dosyan.php?sifre=benim_ozel_sifrem");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "post_title=Başlık&post_content=İçerik&resim_url=https://www.r10.net/images/logom7.png");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
    $server_output = curl_exec ($ch);
    
    curl_close ($ch);
  • 25-07-2014, 10:25:32
    #5
    Üyeliği durduruldu
    jebias adlı üyeden alıntı: mesajı görüntüle
    Şöyle yaparsan olur büyük ihtimalle hocam;

    <?php
    
    if(!$_POST || $_GET['sifre'] != 'benim_ozel_sifrem') 
    	die();
    
    /**
     * Post dizisi, buraya bir çok özellik gelebilir tamamını codex sayfasından görebilirsin
     */
    $post_data = array();
    
    foreach ($_POST as $key => $value) {
          if($key != 'resim_url')
    	$post_data[$key] = $value;
    }
    
    $post_id = wp_insert_post( $post_data ); //$post_id eklediğimiz yaznının ID'si şimdi buna özel alan vs. ekleyebiliriz
    
    /**
     * Post'umuza özel alan ekledik
     */
    add_post_meta($post_id, 'ozel_alan_adi', 'Özel alan değeri', true);
    
    /**
     * $image_url uzaktaki resmin url si olmalı
     */
    $image_url = $_POST['resim_url'];
    
    /**
     * Öne çıkarılmış görseli ekliyeceğiz
     */
    $upload_dir = wp_upload_dir();
    $image_data = file_get_contents($image_url);
    $filename = basename($image_url);
    if(wp_mkdir_p($upload_dir['path']))
        $file = $upload_dir['path'] . '/' . $filename;
    else
        $file = $upload_dir['basedir'] . '/' . $filename;
    file_put_contents($file, $image_data);
    
    $wp_filetype = wp_check_filetype($filename, null );
    $attachment = array(
        'post_mime_type' => $wp_filetype['type'],
        'post_title' => sanitize_file_name($filename),
        'post_content' => '',
        'post_status' => 'inherit'
    );
    $attach_id = wp_insert_attachment( $attachment, $file, $post_id );
    require_once(ABSPATH . 'wp-admin/includes/image.php');
    $attach_data = wp_generate_attachment_metadata( $attach_id, $file );
    wp_update_attachment_metadata( $attach_id, $attach_data );
    
    set_post_thumbnail( $post_id, $attach_id );
    Bu dosyayı WP sitene at, daha sonra uzaktan ekletmek için cURL ile data post edicez onuda şöyle;

    $ch = curl_init();
    
    curl_setopt($ch, CURLOPT_URL,"http://wpsiten.com/wp-dosyan.php?sifre=benim_ozel_sifrem");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "post_title=Başlık&post_content=İçerik&resim_url=https://www.r10.net/images/logom7.png");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
    $server_output = curl_exec ($ch);
    
    curl_close ($ch);
    Teşekkürler deneyip bilgi vereceğim, benim aslen yapmak istediğim işlem zaten php ile uzaktan aldığım verileri wp panelde bir menü açıp çekiyorum oraya çektiğim verileri de siteye yazı olarak eklemek.

    Deneyip bilgi vereceğim teşekkürler.
  • 26-07-2014, 01:13:16
    #6
    Üyeliği durduruldu
    jebias adlı üyeden alıntı: mesajı görüntüle
    Şöyle yaparsan olur büyük ihtimalle hocam;

    <?php
    
    if(!$_POST || $_GET['sifre'] != 'benim_ozel_sifrem') 
    	die();
    
    /**
     * Post dizisi, buraya bir çok özellik gelebilir tamamını codex sayfasından görebilirsin
     */
    $post_data = array();
    
    foreach ($_POST as $key => $value) {
          if($key != 'resim_url')
    	$post_data[$key] = $value;
    }
    
    $post_id = wp_insert_post( $post_data ); //$post_id eklediğimiz yaznının ID'si şimdi buna özel alan vs. ekleyebiliriz
    
    /**
     * Post'umuza özel alan ekledik
     */
    add_post_meta($post_id, 'ozel_alan_adi', 'Özel alan değeri', true);
    
    /**
     * $image_url uzaktaki resmin url si olmalı
     */
    $image_url = $_POST['resim_url'];
    
    /**
     * Öne çıkarılmış görseli ekliyeceğiz
     */
    $upload_dir = wp_upload_dir();
    $image_data = file_get_contents($image_url);
    $filename = basename($image_url);
    if(wp_mkdir_p($upload_dir['path']))
        $file = $upload_dir['path'] . '/' . $filename;
    else
        $file = $upload_dir['basedir'] . '/' . $filename;
    file_put_contents($file, $image_data);
    
    $wp_filetype = wp_check_filetype($filename, null );
    $attachment = array(
        'post_mime_type' => $wp_filetype['type'],
        'post_title' => sanitize_file_name($filename),
        'post_content' => '',
        'post_status' => 'inherit'
    );
    $attach_id = wp_insert_attachment( $attachment, $file, $post_id );
    require_once(ABSPATH . 'wp-admin/includes/image.php');
    $attach_data = wp_generate_attachment_metadata( $attach_id, $file );
    wp_update_attachment_metadata( $attach_id, $attach_data );
    
    set_post_thumbnail( $post_id, $attach_id );
    Bu dosyayı WP sitene at, daha sonra uzaktan ekletmek için cURL ile data post edicez onuda şöyle;

    $ch = curl_init();
    
    curl_setopt($ch, CURLOPT_URL,"http://wpsiten.com/wp-dosyan.php?sifre=benim_ozel_sifrem");
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "post_title=Başlık&post_content=İçerik&resim_url=https://www.r10.net/images/logom7.png");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    
    $server_output = curl_exec ($ch);
    
    curl_close ($ch);
    Hocam herşey okey çok teşekkürler fakat öne çıkan resmi yüklüyor ama seçmiyor neden olabilir?
  • 26-07-2014, 10:45:52
    #7
    Sorunu anlamak için; bazı değişkenleri ekrana yazdırtmayı denermisin hocam.

    Şöyle;

    <?php
    
    if(!$_POST || $_GET['sifre'] != 'benim_ozel_sifrem') 
    	die();
    
    /**
     * Post dizisi, buraya bir çok özellik gelebilir tamamını codex sayfasından görebilirsin
     */
    $post_data = array();
    
    foreach ($_POST as $key => $value) {
          if($key != 'resim_url')
    	$post_data[$key] = $value;
    }
    
    $post_id = wp_insert_post( $post_data ); //$post_id eklediğimiz yaznının ID'si şimdi buna özel alan vs. ekleyebiliriz
    
    /**
     * Post'umuza özel alan ekledik
     */
    add_post_meta($post_id, 'ozel_alan_adi', 'Özel alan değeri', true);
    
    /**
     * $image_url uzaktaki resmin url si olmalı
     */
    $image_url = $_POST['resim_url'];
    
    /**
     * Öne çıkarılmış görseli ekliyeceğiz
     */
    $upload_dir = wp_upload_dir();
    $image_data = file_get_contents($image_url);
    $filename = basename($image_url);
    if(wp_mkdir_p($upload_dir['path']))
        $file = $upload_dir['path'] . '/' . $filename;
    else
        $file = $upload_dir['basedir'] . '/' . $filename;
    file_put_contents($file, $image_data);
    
    $wp_filetype = wp_check_filetype($filename, null );
    $attachment = array(
        'post_mime_type' => $wp_filetype['type'],
        'post_title' => sanitize_file_name($filename),
        'post_content' => '',
        'post_status' => 'inherit'
    );
    $attach_id = wp_insert_attachment( $attachment, $file, $post_id );
    require_once(ABSPATH . 'wp-admin/includes/image.php');
    $attach_data = wp_generate_attachment_metadata( $attach_id, $file );
    wp_update_attachment_metadata( $attach_id, $attach_data );
    
    var_dump($post_id);
    var_dump($attach_id);
    var_dump(set_post_thumbnail( $post_id, $attach_id ));
    bu şekilde çalıştırınca, çıktısı ne şekilde oluyor?
  • 26-07-2014, 13:12:37
    #8
    Üyeliği durduruldu
    jebias adlı üyeden alıntı: mesajı görüntüle
    Sorunu anlamak için; bazı değişkenleri ekrana yazdırtmayı denermisin hocam.

    Şöyle;

    <?php
    
    if(!$_POST || $_GET['sifre'] != 'benim_ozel_sifrem') 
    	die();
    
    /**
     * Post dizisi, buraya bir çok özellik gelebilir tamamını codex sayfasından görebilirsin
     */
    $post_data = array();
    
    foreach ($_POST as $key => $value) {
          if($key != 'resim_url')
    	$post_data[$key] = $value;
    }
    
    $post_id = wp_insert_post( $post_data ); //$post_id eklediğimiz yaznının ID'si şimdi buna özel alan vs. ekleyebiliriz
    
    /**
     * Post'umuza özel alan ekledik
     */
    add_post_meta($post_id, 'ozel_alan_adi', 'Özel alan değeri', true);
    
    /**
     * $image_url uzaktaki resmin url si olmalı
     */
    $image_url = $_POST['resim_url'];
    
    /**
     * Öne çıkarılmış görseli ekliyeceğiz
     */
    $upload_dir = wp_upload_dir();
    $image_data = file_get_contents($image_url);
    $filename = basename($image_url);
    if(wp_mkdir_p($upload_dir['path']))
        $file = $upload_dir['path'] . '/' . $filename;
    else
        $file = $upload_dir['basedir'] . '/' . $filename;
    file_put_contents($file, $image_data);
    
    $wp_filetype = wp_check_filetype($filename, null );
    $attachment = array(
        'post_mime_type' => $wp_filetype['type'],
        'post_title' => sanitize_file_name($filename),
        'post_content' => '',
        'post_status' => 'inherit'
    );
    $attach_id = wp_insert_attachment( $attachment, $file, $post_id );
    require_once(ABSPATH . 'wp-admin/includes/image.php');
    $attach_data = wp_generate_attachment_metadata( $attach_id, $file );
    wp_update_attachment_metadata( $attach_id, $attach_data );
    
    var_dump($post_id);
    var_dump($attach_id);
    var_dump(set_post_thumbnail( $post_id, $attach_id ));
    bu şekilde çalıştırınca, çıktısı ne şekilde oluyor?
    post_id değişkeni boş döndüğü için yazıya atamıyormuş. Halledildi teşekkürler.