我正在尝试将 xmlrpc 与 wordpress 一起使用来获取特定自定义类型(称为集合)的帖子。
Wordpress API 文档指出:
wp.getPosts
Parameters:
int blog_id
string username
string password
struct filter: Optional.
string post_type
string post_status
int number
int offset
string orderby
string order
array fields: Optional.
我的问题是在 objc 中用字符串形成一个结构:
我想做这样的事情:
// in .h
typedef struct{
string post_type;
string post_status;
int number;
int offset;
string orderby;
string order;
} wp_filter;
// in .m
wp_filter filter = {@"collection", @"", ... , ... ,@"",@""};
NSArray *fieldsArray = [NSArray arrayWithObjects:@"post_title", nil];
NSArray *postParams = [NSArray arrayWithObjects:@"0", username, password, filter, fieldsArray, nil];
XMLRPCRequest *reqCollections =[[XMLRPCRequest alloc] initWithURL:[NSURL URLWithString:server]];
[reqCollections setMethod:@"wp.getPosts" withParameters:postParams];
XMLRPCResponse *customPostResponse = [XMLRPCConnection sendSynchronousXMLRPCRequest:reqCollections error:nil];
if ([[customPostResponse object] isKindOfClass:[NSArray class]]){
NSArray *collections = [NSArray arrayWithArray:[customPostResponse object]];
NSLog(@"number of collections %i",[collections count]);
for (int i = 0; i < [collections count]; i++) {
NSLog(@"%@", [[collections objectAtIndex:i] description] );
}
}
else {
NSLog(@"response description %@",[[customPostResponse object ] description]);
}