dongshi6969 2013-11-17 20:18
浏览 31
已采纳

从Scrapy间接调用脚本时,不在wordpress中分配的类别

I'm using Scrapy to parse a website and then add these scraped informations to the wordpress blog. So after the scrapy script has parsed a website it sends all data in the json format to php script, which adds them to wordpress. The problem is that when this php script is called from Scrapy, it adds all data correctly EXCEPT assigning the post to the category. Somehow this doesn't work, although it adds the scraped categories to wordpress. It also doesn't automatically insert admin as a post author. There are just two blank fields(in author and categories columns).

What's interesting the php script adds all field correctly when it's run directly(not as a call from Scrapy script). All data are correctly sended to php script. You can see that clearly on screenshot below. The first item was added using Scrapy script, which has called php script(author and categories are missing), the second record was added directly from php script. enter image description here

$post = array(
  'post_content' => 'Content',
  'post_title' => $title,
  'post_status' => 'publish',
  'post_type'   => 'ait-dir-item',
  'tags_input' => "tags",
  'tax_input' => array('ait-dir-item-category' => $last_cat)
);

print_r($post);

$post_id = wp_insert_post($post);
  • 写回答

1条回答 默认 最新

  • dongzhangji4824 2013-11-17 21:24
    关注

    I've found out some temporary solution. We can also add category in the following function:

    wp_set_object_terms($post_id, $last_cat, 'ait-dir-item-category');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站