{"id":335,"date":"2012-02-17T16:57:03","date_gmt":"2012-02-17T16:57:03","guid":{"rendered":"https:\/\/trouble.org\/?p=335"},"modified":"2012-02-17T21:49:48","modified_gmt":"2012-02-17T21:49:48","slug":"command-line-perl-posting-to-wp","status":"publish","type":"post","link":"https:\/\/trouble.org\/?p=335","title":{"rendered":"command line perl posting to WP"},"content":{"rendered":"<p>After looking at about a zillion different options I ended up with Leo Charre&#8217;s <a title=\"WPCLI\" href=\"http:\/\/search.cpan.org\/~leocharre\/WordPress-CLI-1.04\/lib\/WordPress\/CLI.pm\" target=\"_blank\">WordPress CLI<\/a>\u00a0CPAN package for uploading posts&#8230; and after a bit of tinkering got it to work with 3.x WP. \u00a0However&#8230; it didn&#8217;t support tags, which I really needed for the project I&#8217;m working on. \u00a0 This <a title=\"WP\/Java\/Tags\" href=\"http:\/\/stackoverflow.com\/questions\/1731790\/tagging-posts-via-wordpress-xmlrpc\" target=\"_blank\">handy pointer<\/a> to how to do it to java saved my bacon: it turns out that making a very small modification to the code enabled tagging.<\/p>\n<p>Why WP doesn&#8217;t support this natively is entirely beyond me. \u00a0But putting the magic &#8220;mt_keywords&#8221; in the struct with w\/e values you want seems to do the job. \u00a0Small change to the perl code in case anyone else is looking for this stuff (diff\/etc. sent to LC, of course.) \u00a0 Using the mod&#8217;d code you can do things like (added the -T for tags):<\/p>\n<div class=\"codecolorer-container text blackboard\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"text codecolorer\">wordpress-upload-post -d post-text-file \u00a0-t &quot;Post Title&quot; -c &quot;Nmap-Category&quot; -T &quot;red fish, blue fish, two fish&quot;<\/div><\/div>\n<p>Of course you can&#8217;t use 2 subcategories with the same name in the WP XMLRPC interface either (why they test for names vs. id&#8217;s&#8230;.), but that&#8217;s just another sad tale in tech. \u00a0The salient line:<\/p>\n<div class=\"codecolorer-container perl blackboard\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"perl codecolorer\"><span class=\"re4\">&lt;pre&gt;<\/span><span class=\"kw1\">if<\/span> <span class=\"br0\">&#40;<\/span><span class=\"re0\">$opt_T<\/span><span class=\"br0\">&#41;<\/span><span class=\"br0\">&#123;<\/span> <span class=\"re0\">$struct<\/span><span class=\"sy0\">-&gt;<\/span><span class=\"br0\">&#123;<\/span>mt_keywords<span class=\"br0\">&#125;<\/span> <span class=\"sy0\">=<\/span> <span class=\"re0\">$opt_T<\/span><span class=\"sy0\">;<\/span> <span class=\"br0\">&#125;<\/span><span class=\"sy0\">&lt;\/<\/span>pre<span class=\"sy0\">&gt;<\/span><\/div><\/div>\n<p>Perl program attached, but needs the supporting libs from CPAN.<\/p>\n<p>[attachments]<\/p>\n<!-- WP Attachments -->\r\n        <div style=\"width:100%;margin:10px 0 10px 0;\">\r\n            <h3>Attachments<\/h3>\r\n        <ul class=\"post-attachments\"><li class=\"post-attachment mime-application-x-perl\"><a href=\"https:\/\/trouble.org\/wp-content\/uploads\/2012\/02\/wordpress-upload-post.pl\">wordpress-upload-post<\/a> <small>(ERROR)<\/small><\/li><\/ul><\/div>","protected":false},"excerpt":{"rendered":"<p>After looking at about a zillion different options I ended up with Leo Charre&#8217;s WordPress CLI\u00a0CPAN package for uploading posts&#8230; and after a bit of tinkering got it to work with 3.x WP. \u00a0However&#8230; it didn&#8217;t support tags, which I really needed for the project I&#8217;m working on. \u00a0 This handy pointer to how to [&hellip;]<\/p>\n","protected":false},"author":44,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[31,46,6],"tags":[79,326,78,77],"class_list":["post-335","post","type-post","status-publish","format-standard","hentry","category-code","category-perl","category-tech","tag-cpan","tag-perl","tag-tags","tag-wp-sucks"],"_links":{"self":[{"href":"https:\/\/trouble.org\/index.php?rest_route=\/wp\/v2\/posts\/335","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/trouble.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/trouble.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/trouble.org\/index.php?rest_route=\/wp\/v2\/users\/44"}],"replies":[{"embeddable":true,"href":"https:\/\/trouble.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=335"}],"version-history":[{"count":17,"href":"https:\/\/trouble.org\/index.php?rest_route=\/wp\/v2\/posts\/335\/revisions"}],"predecessor-version":[{"id":337,"href":"https:\/\/trouble.org\/index.php?rest_route=\/wp\/v2\/posts\/335\/revisions\/337"}],"wp:attachment":[{"href":"https:\/\/trouble.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=335"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/trouble.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=335"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/trouble.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=335"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}