通过XML-RPC为WordPress帖子设置特色图像(set featured image for WordPress post via XML-RPC)
大约6个月前,有一个WordPress API的更新,允许设置帖子的缩略图(或特色)图像。
http://www.maxcutler.com/2012/04/04/xml-rpc-in-wordpress-3-4/
我正在尝试使用它,但它不适合我。 我想知道我可能做错了什么。 我正在调用XML-RPC newPost方法来创建帖子并在媒体库中传递现有资产的媒体ID(在媒体库中称为attachment_id)正在创建新帖子并且所有其他属性都在设置,除了特色图像。
我在word-wp-xmlrpc-server.php中验证了我的wordpress api版本,我确实在新的帖子功能部分看到了评论:“* post_thumbnail - 用作帖子缩略图/特色的媒体项目的ID图片”
所有其他属性都在工作。 我可以通过XML-RPC将新图像添加到媒体库。 我可以创建和更新帖子并设置其标签,标题,说明,自定义字段值和类别。 当我尝试设置post_thumbnail值时,我没有收到任何错误。 即使我传入一个不存在的媒体ID,这似乎很奇怪。
About 6 months ago there was an update to the WordPress API which allows setting a post's thumbnail (or featured) image.
http://www.maxcutler.com/2012/04/04/xml-rpc-in-wordpress-3-4/
I'm trying to use it but it's not working for me. I'd like to know what I may be doing wrong. I'm calling the XML-RPC newPost method to create a post and passing the Media ID of an existing asset in the media library (known as the attachment_id in the media library) The new post is being created and all the other properties are being set, except for the featured image.
I verified my version of the wordpress api, and sure enough in class-wp-xmlrpc-server.php I see the comment in the new post function section: "* post_thumbnail - ID of a media item to use as the post thumbnail/featured image"
All the other properties are working. I can add new images to the media library via XML-RPC. I can create and update posts and set their tags, titles, descriptions, custom field values, and categories. I don't get any errors when I try to set the post_thumbnail value. Even if I pass in a non-existent media id, which seems odd.
原文:https://stackoverflow.com/questions/12355922
最满意答案
我终于找到了如何完成我的功能! 我在MDN上读到,特定字符串函数“startsWith”仅适用于Firefox和Chrome。 请看这个链接: https : //developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith最好的解决方案是创建一个名为startsWith的自定义函数。 请在stackOverflow上查看此问题以获取更多说明如何检查字符串“StartsWith”是否为另一个字符串?
这是我最终得到的代码:
//startsWith function from topic above if (typeof String.prototype.startsWith != 'function') { String.prototype.startsWith = function (str){ return this.slice(0, str.length) == str; }; } function fixCordovaOutboundLinks() { var allElements = document.getElementsByTagName('a'); for (var i = 0, n = allElements.length; i < n; i++) { var url = allElements[i].getAttribute('href'); if(url != null) { if(url.startsWith("http")) { console.log("el " + url); allElements[i].onclick = function(event) { event.preventDefault(); alert('URL opens: ' + url); var ref = window.open(url, '_blank', 'location=yes'); }; } } } }
I finnaly figured out how to complete my function! I read over at MDN that the particular string function "startsWith" only works in Firefox and Chrome. Se this link: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith The best solution for this is to create a custom function named startsWith. Se this question here at stackOverflow for further instructions How to check if a string "StartsWith" another string?
Here is the code that i ended up with:
//startsWith function from topic above if (typeof String.prototype.startsWith != 'function') { String.prototype.startsWith = function (str){ return this.slice(0, str.length) == str; }; } function fixCordovaOutboundLinks() { var allElements = document.getElementsByTagName('a'); for (var i = 0, n = allElements.length; i < n; i++) { var url = allElements[i].getAttribute('href'); if(url != null) { if(url.startsWith("http")) { console.log("el " + url); allElements[i].onclick = function(event) { event.preventDefault(); alert('URL opens: ' + url); var ref = window.open(url, '_blank', 'location=yes'); }; } } } }
相关问答
更多-
TCP/IP模型是一个________。[2023-10-02]
a -
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
你只是从json响应中严重提取了你的列表。 您应该返回data属性。 对此最好的位置是直接服务: export class RoleService { roles: Array
; constructor(public http: Http) { } getRoles(){ return this.http.get('http://localhost:3000/api/roles/') .map(response => re ... -
如何在角度http inteceptor中以异步样式缓存http请求?(How to cache http requests in async style in angular http inteceptor?)[2024-02-02]
我认为您的代码很好,您所要做的就是share新令牌的请求。 refreshAccessToken(): Observable{ const refreshTokenUrl = this.urlsService.getUrl(Urls.TOKEN); const httpParams = new HttpParams() .append('grant_type', 'refresh_token') . ... -
Angular2链接http请求(Angular2 chain http request)[2023-08-05]
这个答案不是特定于Angular的,但主要是展示了如何将Reactive运算符链接在一起以获取所需内容。 你可以做如下的事情(警告:未经测试的代码): import 'rxjs/add/operator/map'; import 'rxjs/add/operator/switch'; export class Foo { bar() { const httpClient: HttpClient = /* Your HTTP client here */; httpC ... -
我终于找到了如何完成我的功能! 我在MDN上读到,特定字符串函数“startsWith”仅适用于Firefox和Chrome。 请看这个链接: https : //developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith最好的解决方案是创建一个名为startsWith的自定义函数。 请在stackOverflow上查看此问题以获取更多说明如何检查字符串“StartsWith”是否为另一 ...
-
我已通过添加以下几行代码来解决该问题: $http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded;charset=utf-8"; var payload = $.param({ grant_type: 'client_credentials' }); grant_type现在通过键,'client_credentials'是值。 整个请求看起来像这样: function ...
-
如果您可以向我们展示login()函数的样子,那可能会有所帮助,但是现在看起来您没有正确使用$httpBackend 。 看看http://docs.angularjs.org/api/ngMock/service/$httpBackend 。 你应该在$httpBackend上设置一个期望值,然后调用你的login()函数,然后在$httpBackend上调用flush() 。 It might help if you can show us what the login() function looks ...
-
1.1.4目前需要在$http.get中执行$http.get $scope.$apply (不知道这是一个bug)。 因为ng-click会为你做$scope.apply ,在你的指令中你必须这样做。 AFAIK范围。$ eval不会触发$ digest,所以请尝试$scope.$apply(attrs.pulldown) ; 1.1.4 currently requires to do the $http.get in $scope.$apply (don't know this is a bug). ...
-
从您的评论中我不认为它与Zones有任何关系。 @Input属性更改时,您需要更新辅助组件。 export class SecondaryComponent { private _myProperty: any; @Input() set myProperty(val: any) { this._myProperty = val; this.update(); } update() { //instead of ngOnInit j ...