2012-09-10 67 views
3

大約6個月前有一個更新WordPress的API,它允許設置後的縮略圖(或功能)的圖像。集特色圖片

http://www.maxcutler.com/2012/04/04/xml-rpc-in-wordpress-3-4/

我試圖使用它,但它不是爲我工作。我想知道我可能做錯了什麼。我打電話的XML-RPC newPost方法來創建一個帖子,並在媒體庫通過現有資產的媒體ID(被稱爲媒體庫中attachment_id)正在創建新的崗位和所有其他屬性都被設置,除了特色圖片。

我驗證了我的wordpress api版本,並且確實足夠在class-wp-xmlrpc-server.php中查看新帖子功能部分中的註釋: 「* post_thumbnail - 用作媒體項目的ID後縮略圖/特色形象」

所有其他屬性都在工作。我可以通過XML-RPC將新圖像添加到媒體庫。我可以創建和更新帖子並設置他們的標籤,標題,說明,自定義字段值和類別。我嘗試設置post_thumbnail值時沒有遇到任何錯誤。即使我傳入一個不存在的媒體ID,這看起來很奇怪。

回答

0

我試圖做同樣的我的Ruby腳本和使用XML RPC API。

  • 首先初始化並獲得連接到你的WordPress網站:

    wp = Rubypress::Client.new(:host => "your host", 
        :username => "test", 
        :password => "test", 
        :path => "yourhost/xmlrpc.php" 
    ) 
    
  • 上傳您要爲特色的圖像的圖像。

    wp.uploadFile(:data => { :name => File.basename(FILENAME), 
           :type => "image/png", 
           :bits => XMLRPC::Base64.new(File.open(FILENAME).read) 
          } 
         ) 
    
  • 使用getMediaItem方法獲得附件ID。

    attach = wp.getMediaItem(:blog_id => 0, :attachment_id => img_id.to_i) 
    
    • 現在創建使用newPost方法

      wp.newPost(:blog_id => 0, # 0 unless using WP Multi-Site, then use the blog id 
      :content => { 
            :post_status => "draft", 
            :post_date => Time.now, 
            :post_content => "This is the body", 
            :post_title => "test title best!", 
            :post_name => "test best", 
            :post_author => 1, 
            :post_type=>'post', 
            :post_thumbnail => attach['attachment_id'] 
            :terms_names => { 
             :category => ['Category One','Category'], 
             :post_tag => ['Tag One','Tag Two', 'Tag Three'] 
                 }, 
      
            } 
      
      
      ) 
      
  • 後檢查由getPost方法其結果將返回後

    get_data = wp.getPost(:post_id => new_post_resp.to_i, :blog_id => 0) 
    

你應該參考以下鏈接。這些都是當我面臨着同樣的問題,我發現: