描述
示例: query_posts( args )
功能: 查询文章
参数
args
(Object) (Required)
查询参数
author
(Int)(Optional)
仅此作者ID撰写
author_in
(Array[Int])(Optional)
含这些作者ID
author_not_in
(Array[Int])(Optional)
不含这些作者ID
post
(Int)(Optional)
仅这篇文章ID
post_in
(Array[Int])(Optional)
含这些文章ID
post_not_in
(Array[Int])(Optional)
不含这些文章ID
keyword
(String)(Optional)
标题、别名、摘要包含这个关键词
parent
(Int)(Optional)
父级ID
hierarchical
(Boolean)(Optional)
层级显示
has_password
(Boolean)(Optional)
有密码
post_password
(String)(Optional)
含这个密码的文章
post_type
(String)(Optional)
文章类型(页面:page,文章:article)
status
(String)(Optional)
状态(可选:publish/pending/draft)
orderby
(String)(Optional)
排序字段(可选:id/author/title/slug/date/parent/rand,默认:order序号)
order
(String)(Optional)
排序(可选:ASC/DESC,默认:DESC倒序)
posts_per_page
(Int)(Optional)
每页文章数量(跟随Option设置:posts_per_page,默认:10)
current_page
(Int)(Optional)
当前页码(默认:1)
comment_count
(Object)(Optional)
评论数查询
- value
(Number)(Required)
评论数
- compare
(String)(Required)
比较条件(可选:=/!=/>/>=/</<=,默认:=)
date_query
(Object)(Optional)
日期查询
- after
(Int)(Required)
此时间戳之后
- before
(Int)(Optional)
此时间戳之前(默认:服务器当前时间戳)
tax_query
(Object)(Optional)
分类法查询
- relation
(String)(Required)
条件集合关系(可选:AND/OR,默认:AND)
- opts
(Array)(Required)
查询条件
- taxonomy
(String)(Required)
分类法(文章默认:category、tag)
- terms
(Array[Int/String])(Required)
该分类法中的分类ID或别名
- operator
(String)(Optional)
结果关系(可选:IN/NOT IN,默认:IN)
meta_query
(Object)(Optional)
元数据查询
- relation
(String)(Required)
条件集合关系(可选:AND/OR,默认:AND)
- opts
(Array)(Required)
查询条件
- key
(String)(Required)
元数据字段名
- value
(Int/String/Array)(Required)
比较值
- compare
(String)(Optional)
结果关系(对于Int:=/!=/>/>=/</<=;对于String:=/!=/LIKE/NOT LIKE;对于Array:IN/NOT IN/BETWEEN/NOT BETWEEN)
返回
(Object)
示例
{
"data": [
{
"id": 10,
"author": 1,
"created_time": 1645515387384,
"content_type": "block",
"title": "将iOS备份迁移到Nas",
"excerpt": "",
"status": "publish",
"slug": "%E5%B0%86ios%E5%A4%87%E4%BB%BD%E8%BF%81%E7%A7%BB%E5%88%B0nas",
"modified_time": 1652254560000,
"parent": 0,
"order": 0,
"post_type": "article",
"comment_status": true,
"comment_count": 0,
"has_password": false,
"author_name": "Panda",
"taxonomies": {
"category": [
{
"id": 11,
"name": "图标",
"slug": "icons",
"parent": 17,
"count": 3
}
],
"tag": [
{
"id": 12,
"name": "box",
"slug": "box",
"parent": 0,
"count": 2
}
]
},
"metas": {
"_nv_thumbnail": "/uploads/2022/02/sample_image.jpg"
}
}
],
"pagination": {
"current_page": 1,
"posts_per_page": 10,
"total": 1
}
}
参数说明
data(Array)
文章列表查询结果
id(Boolean)
文章id
author(Boolean)
作者ID
created_time(Boolean)
创建时间戳
content_type(String)
文章内容类型(默认:block块)
title(String)
标题
excerpt(String)
摘要
status(String)
状态(publish、pending、draft)
slug(String)
文章别名
modified_time(Int)
修改时间戳
parent(Int)
父级ID
order(Int)
序号
post_type(String)
文章类型(页面:page,文章:article)
comment_status(Boolean)
评论启用状态
comment_count(Int)
评论数
has_password(Boolean)
文章是否有密码
author_name(String)
作者名称
metas(Object)
文章所有的元数据
taxonomies(Object)
文章分类法(文章默认:category、tag)
- [taxonomy_name]
(Array)
分类法列表
- id
(Int)
分类ID
- name
(String)
分类名称
- slug
(String)
分类别名
- parent
(Int)
父分类ID
- count
(Int)
该分类包含文章数量
pagination(Object)
查询页码信息
- current_page
(Int)
当前页码
- posts_per_page
(Int)
分页数据量
- total
(Int)
总量