且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Wordpress API 按类别获取帖子

更新时间:2023-01-19 18:21:34

我最终通过使用可选的过滤器参数成功地实现了这一点.根据文档,这些是以下可接受的过滤器参数.

I managed to get this working in the end by using the optional filters parameter. According to the documentation these are the following accepted filter parameters.

结构过滤器:可选.字符串 post_type字符串 post_status整数整数偏移字符串排序字符串顺序

struct filter: Optional. string post_type string post_status int number int offset string orderby string order

出于好奇,我通过将以下内容添加到 getposts 方法下的 class-wp-xmlrpc-server.php 来发送类别"过滤器

Out of curiousity I sent over a 'category' filter by adding the following to class-wp-xmlrpc-server.php under the getposts method

if(isset($filter['category']))
     $query['category'] = absint($filter['category']);

wp_get_recent_posts{$query); 方法被调用之前

它奏效了!Wordpress 似乎从他们的文档中遗漏了一些过滤器参数.

and it worked! It seems like Wordpress have left out a few filter parameters from their documentation.

您还可以通过传递s"作为过滤器来发送搜索过滤器

You can also send over a search filter by passing over 's' as the filter

$query['s'] = $filter['s'];