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');
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 fluent里模拟降膜反应的UDF编写
  • ¥15 MYSQL 多表拼接link
  • ¥15 关于某款2.13寸墨水屏的问题
  • ¥15 obsidian的中文层级自动编号
  • ¥15 同一个网口一个电脑连接有网,另一个电脑连接没网
  • ¥15 神经网络模型一直不能上GPU
  • ¥15 pyqt怎么把滑块和输入框相互绑定,求解决!
  • ¥20 wpf datagrid单元闪烁效果失灵
  • ¥15 券商软件上市公司信息获取问题
  • ¥100 ensp启动设备蓝屏,代码clock_watchdog_timeout