• 13-11-2016, 19:44:34
    #1
    Arkadaşlar basit bir bot yapıyorum kendim kullanmam için.
    Botta resmi kendi sunucuma alıyorum adresimde belli.
    Fakat ben bu resmi Post'a nasıl öne çıkarılmış olarak ekletebilirim, özel alana ekletebiliyorum fakat öne çıkartamıyorum.
  • 13-11-2016, 20:40:57
    #2
    Reklam67 adlı üyeden alıntı: mesajı görüntüle
    Arkadaşlar basit bir bot yapıyorum kendim kullanmam için.
    Botta resmi kendi sunucuma alıyorum adresimde belli.
    Fakat ben bu resmi Post'a nasıl öne çıkarılmış olarak ekletebilirim, özel alana ekletebiliyorum fakat öne çıkartamıyorum.
        function insert_image2post( $postid, $image, $featured = false ) {
          global $wpdb;
    
            $post_title = $wpdb->get_var("SELECT $wpdb->posts.post_title FROM $wpdb->posts WHERE ID = '$postid'");
            if( is_null( $post_title ) )
                return false;
    
            $post_name = sanitize_title( $post_title );
    
            if( !class_exists( 'WP_Http' ) )
              include_once( ABSPATH . WPINC. '/class-http.php' );
    
            $photo = new WP_Http();
            $photo = $photo->request($image);
            if( $photo['response']['code'] != 200 )
                return false;
    
            $attachment = wp_upload_bits( $post_name . '.jpg', null, $photo['body'], date("Y/m") );
            if( !empty( $attachment['error'] ) )
                return false;
    
            $filetype = wp_check_filetype( basename( $attachment['file'] ), null );
    
            $postinfo = array(
                'post_mime_type'    => $filetype['type'],
                'post_title'        => $post_title,
                'post_content'      => '',
                'post_excerpt'      => '',
                'post_status'       => 'inherit'
            );
            $filename = $attachment['file'];
            $attach_id = wp_insert_attachment( $postinfo, $filename, $postid );
    
            if( !function_exists( 'wp_generate_attachment_data' ) )
                require_once(ABSPATH . "wp-admin" . '/includes/image.php');
            $attach_data = wp_generate_attachment_metadata( $attach_id, $filename );
            wp_update_attachment_metadata( $attach_id,  $attach_data );
            if( $featured )
                add_post_meta($postid, '_thumbnail_id', $attach_id);
            return array($attach_id, $attachment['url']);
        }
  • 13-11-2016, 21:18:04
    #3
    codeofali adlı üyeden alıntı: mesajı görüntüle
        function insert_image2post( $postid, $image, $featured = false ) {
          global $wpdb;
    
            $post_title = $wpdb->get_var("SELECT $wpdb->posts.post_title FROM $wpdb->posts WHERE ID = '$postid'");
            if( is_null( $post_title ) )
                return false;
    
            $post_name = sanitize_title( $post_title );
    
            if( !class_exists( 'WP_Http' ) )
              include_once( ABSPATH . WPINC. '/class-http.php' );
    
            $photo = new WP_Http();
            $photo = $photo->request($image);
            if( $photo['response']['code'] != 200 )
                return false;
    
            $attachment = wp_upload_bits( $post_name . '.jpg', null, $photo['body'], date("Y/m") );
            if( !empty( $attachment['error'] ) )
                return false;
    
            $filetype = wp_check_filetype( basename( $attachment['file'] ), null );
    
            $postinfo = array(
                'post_mime_type'    => $filetype['type'],
                'post_title'        => $post_title,
                'post_content'      => '',
                'post_excerpt'      => '',
                'post_status'       => 'inherit'
            );
            $filename = $attachment['file'];
            $attach_id = wp_insert_attachment( $postinfo, $filename, $postid );
    
            if( !function_exists( 'wp_generate_attachment_data' ) )
                require_once(ABSPATH . "wp-admin" . '/includes/image.php');
            $attach_data = wp_generate_attachment_metadata( $attach_id, $filename );
            wp_update_attachment_metadata( $attach_id,  $attach_data );
            if( $featured )
                add_post_meta($postid, '_thumbnail_id', $attach_id);
            return array($attach_id, $attachment['url']);
        }
    Hocam yapamadım bu şekilde, elimde post ID ve resim linki var kendi sunucuma eklenmiş olarak ama beceremedim
  • 13-11-2016, 21:21:40
    #4
    Reklam67 adlı üyeden alıntı: mesajı görüntüle
    Hocam yapamadım bu şekilde, elimde post ID ve resim linki var kendi sunucuma eklenmiş olarak ama beceremedim
    skype: oktayozge ( ekledikten sonra pm atın lütfen )
  • 13-11-2016, 22:12:42
    #5
    Teşekküler hocam sorunu çözdük