POST
To fetch a WordPress post with the REST API the following URL is used :
https://admin.ki-leierbud.lu/wp-json/wp/v2/posts/xxx (xxx = post ID)
Example :
https://admin.ki-leierbud.lu/wp-json/wp/v2/posts/410
CATEGORY
To fetch a WordPress category post with the REST API the following URL is used :
https://admin.ki-leierbud.lu/wp-json/wp/v2/categories/yyy (yyy = category ID)
Example :
https://admin.ki-leierbud.lu/wp-json/wp/v2/categories/91
List of 100 categories
To fetch the first 100 categories from a WordPress web site :
https://admin.ki-leierbud.lu/wp-json/wp/v2/categories?per_page=100
[{"id":77,"count":0,"description":"","link":"https:\/\/admin.ki-leierbud.lu\/de\/archives\/category\/wissen\/ausbildung","name":"Ausbildung","slug":"ausbildung","taxonomy":"category","parent":29,"meta":[],"_links":{"self":[{"href":"https:\/\/admin.ki-leierbud.lu\/wp-json\/wp\/v2\/categories\/77","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/admin.ki-leierbud.lu\/wp-json\/wp\/v2\/categories"}],"about":[{"href":"https:\/\/admin.ki-leierbud.lu\/wp-json\/wp\/v2\/taxonomies\/category"}],"up":[{"embeddable":true,"href":"https:\/\/admin.ki-leierbud.lu\/wp-json\/wp\/v2\/categories\/29"}],"wp:post_type":[{"href":"https:\/\/admin.ki-leierbud.lu\/wp-json\/wp\/v2\/posts?categories=77"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},
{"id":212,"count":2,"description":"","link":"https:\/\/admin.ki-leierbud.lu\/de\/archives\/category\/wissen\/fragen\/ausbildung-ki","name":"Ausbildung KI","slug":"ausbildung-ki","taxonomy":"category","parent":35,"meta":[],"_links":{"self":[{"href":"https:\/\/admin.ki-leierbud.lu\/wp-json\/wp\/v2\/categories\/212","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/admin.ki-leierbud.lu\/wp-json\/wp\/v2\/categories"}],"about":[{"href":"https:\/\/admin.ki-leierbud.lu\/wp-json\/wp\/v2\/taxonomies\/category"}],"up":[{"embeddable":true,"href":"https:\/\/admin.ki-leierbud.lu\/wp-json\/wp\/v2\/categories\/35"}],"wp:post_type":[{"href":"https:\/\/admin.ki-leierbud.lu\/wp-json\/wp\/v2\/posts?categories=212"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},
{"id":33,"count":0,"description":"","link":"https:\/\/admin.ki-leierbud.lu\/pt\/archives\/category\/conhecimento","name":"Conhecimento","slug":"conhecimento","taxonomy":"category","parent":0,"meta":[],"_links":{"self":[{"href":"https:\/\/admin.ki-leierbud.lu\/wp-json\/wp\/v2\/categories\/33","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/admin.ki-leierbud.lu\/wp-json\/wp\/v2\/categories"}],"about":[{"href":"https:\/\/admin.ki-leierbud.lu\/wp-json\/wp\/v2\/taxonomies\/category"}],"wp:post_type":[{"href":"https:\/\/admin.ki-leierbud.lu\/wp-json\/wp\/v2\/posts?categories=33"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},
{"id":27,"count":0,"description":"","link":"https:\/\/admin.ki-leierbud.lu\/fr\/archives\/category\/connaissances","name":"Connaissances","slug":"connaissances","taxonomy":"category","parent":0,"meta":[],"_links":{"self":[{"href":"https:\/\/admin.ki-leierbud.lu\/wp-json\/wp\/v2\/categories\/27","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/admin.ki-leierbud.lu\/wp-json\/wp\/v2\/categories"}],"about":[{"href":"https:\/\/admin.ki-leierbud.lu\/wp-json\/wp\/v2\/taxonomies\/category"}],"wp:post_type":[{"href":"https:\/\/admin.ki-leierbud.lu\/wp-json\/wp\/v2\/posts?categories=27"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}},
Here is the list of the four first categories returned in the JSON file with their parent categories :
- 77 >>> 29
- 212 >>> 35
- 33 >>> 0
- 27 >>> 0
A “0” means that the category has no parent.
Here is a list with the returned categories to view the details provided :
- https://admin.ki-leierbud.lu/wp-json/wp/v2/categories/77
- https://admin.ki-leierbud.lu/wp-json/wp/v2/categories/212
- https://admin.ki-leierbud.lu/wp-json/wp/v2/categories/33
- https://admin.ki-leierbud.lu/wp-json/wp/v2/categories/27
- https://admin.ki-leierbud.lu/wp-json/wp/v2/categories/29
- https://admin.ki-leierbud.lu/wp-json/wp/v2/categories/35
CATEGORY from POST
To extract a category from a post JSON file :
...... {"footnotes":""},"categories":[93],"tags":[201],"class_list":["post-410","post","type-post","status-publish","format-standard","hentry","category-image-style-easy-en-en","tag-simpson"],"translations":{"en":410},"_links":.....
Parent, Grand-parent and top CATEGORIES
To find the parent, grand-parent or top level categories from a post JSON file , we must proceed iteratively:
- fetch the POST JSON file and extract first category ID
- fetch the first CATEGORY JSON file and extract the parent category ID
- if the parent category is not 0, continue to fetch the PARENT CATEGORY JSON file and extract the grand-parent category ID
- if the grand-parent category is not 0, continue to fetch the GRAND-PARENT CATEGORY JSON file and extract the next level category ID