所以getEntityRecords( \'taxonomy\', \'genre\' ) 将向;“列出术语”;端点位于/wp/v2/genre (或/wp/v2/<rest_base> 如果分类法使用自定义rest_base) 在REST API中,由于;“列出术语”;默认情况下,自定义分类的端点使用的参数与/wp/v2/categories (内置的“列表术语”端点category 如果要将结果集限制为特定的术语ID,则可以使用include parameter 像这样:
const termId = 123;
// The optional third parameter is an object which contains arguments for the
// specific REST API endpoint. On successful requests, this will be an array of
// term objects.
const terms = getEntityRecords( \'taxonomy\', \'genre\', { include: [ termId ] } );
console.log( terms && terms[0] ? terms[0].name : terms );
但不是使用
getEntityRecords(), 您可能只想使用
getEntityRecord() 要获取单个术语对象/数据,请执行以下操作:
const termId = 123;
// The third parameter is mandatory and it is the term ID.
const term = getEntityRecord( \'taxonomy\', \'genre\', termId );
console.log( term?.name );
如果您还不知道,可以向
/wp/v2 (例如。
https://example.com/wp-json/wp/v2) 查看所有已注册的路由和端点,以及每个端点的参数。