admin管理员组文章数量:1289788
We have a WordPress 5.4 instance that we query through it's API. I am hoping to find a solution for the following problem that works with newer versions as well.
What I need is an intersection when fetching posts by category: Each returned post needs to be in category 1 AND in category 2. As far as I know, this is not possible with a vanilla WordPress installation, though that may change in some later version.
This problem has been discussed before, and some plug-ins have been recommended to restore a filter
query parameter that was supported in WordPress 4.6 and earlier versions. However, these plug-ins all seem to have been abandoned or not to do what I need.
I tried using the code from the simplest of these plug-ins, but it does not work: When filtering post with ?filter[categories]=1
I still get all posts, while ?categories=1
only gives me a few posts (as expected). I didn't even get to test a more complex query. The condition in this code snippet evaluates to true, so the filter
param seems not to be recognized:
// Bail out if no filter parameter is set.
if ( empty( $request['filter'] ) || ! is_array( $request['filter'] ) ) {
return $args;
}
What would be the simplest or most standard solution for us to make filtering for category 1 AND category 2 work?
本文标签: categoriesWordPress 54 and higher Filter posts by category 1 AND category 2 in API requests
版权声明:本文标题:categories - WordPress 5.4 and higher: Filter posts by category 1 AND category 2 in API requests 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741485104a2381363.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论