How to filter a matched value with custom key using WP REST API?

Question

Take a look this JSON result

[
{
"id": 110,
"date": "2020-12-02T22:25:34",
"date_gmt": "2020-12-02T22:25:34",
"guid": {
"rendered": "http://wp-dev.test/individual/sj57968/"
},
"modified": "2020-12-02T22:28:03",
"modified_gmt": "2020-12-02T22:28:03",
"slug": "sj57968",
"status": "publish",
"type": "hra-ind",
"link": "http://wp-dev.test/individual/sj57968/",
"title": {
"rendered": "Amir Sadollaher"
},
"template": "",
"crb_individual_picture": "",
"crb_individual_id": "sj57968",
"_links": {
"self": [
{
"href": "http://wp-dev.test/wp-json/wp/v2/hra-ind/110"
}
],
"collection": [
{
"href": "http://wp-dev.test/wp-json/wp/v2/hra-ind"
}
],
"about": [
{
"href": "http://wp-dev.test/wp-json/wp/v2/types/hra-ind"
}
],
"wp:attachment": [
{
"href": "http://wp-dev.test/wp-json/wp/v2/media?parent=110"
}
],
"curies": [
{
"name": "wp",
"href": "https://api.w.org/{rel}",
"templated": true
}
]
}
},
{
"id": 71,
"date": "2020-10-29T23:46:54",
"date_gmt": "2020-10-29T23:46:54",
"guid": {
"rendered": "http://wp-dev.test/?post_type=hra-ind&p=71"
},
"modified": "2020-12-03T12:31:38",
"modified_gmt": "2020-12-03T12:31:38",
"slug": "sj43009",
"status": "publish",
"type": "hra-ind",
"link": "http://wp-dev.test/individual/sj43009/",
"title": {
"rendered": "Mohamad Moghiseh"
},
"template": "",
"crb_individual_picture": "",
"crb_individual_id": "sj43009",
"_links": {
"self": [
{
"href": "http://wp-dev.test/wp-json/wp/v2/hra-ind/71"
}
],
"collection": [
{
"href": "http://wp-dev.test/wp-json/wp/v2/hra-ind"
}
],
"about": [
{
"href": "http://wp-dev.test/wp-json/wp/v2/types/hra-ind"
}
],
"wp:attachment": [
{
"href": "http://wp-dev.test/wp-json/wp/v2/media?parent=71"
}
],
"curies": [
{
"name": "wp",
"href": "https://api.w.org/{rel}",
"templated": true
}
]
}
},
]

I’m trying to filter the value with slug keyword

Using this url:

http://wp-dev.test/wp-json/wp/v2/hra-ind?slug=sj43009

It returned this JSON

[
{
"id": 71,
"date": "2020-10-29T23:46:54",
"date_gmt": "2020-10-29T23:46:54",
"guid": {
"rendered": "http://wp-dev.test/?post_type=hra-ind&p=71"
},
"modified": "2020-12-03T12:31:38",
"modified_gmt": "2020-12-03T12:31:38",
"slug": "sj43009",
"status": "publish",
"type": "hra-ind",
"link": "http://wp-dev.test/individual/sj43009/",
"title": {
"rendered": "Mohamad Moghiseh"
},
"template": "",
"crb_individual_picture": "",
"crb_individual_id": "sj43009",
"_links": {
"self": [
{
"href": "http://wp-dev.test/wp-json/wp/v2/hra-ind/71"
}
],
"collection": [
{
"href": "http://wp-dev.test/wp-json/wp/v2/hra-ind"
}
],
"about": [
{
"href": "http://wp-dev.test/wp-json/wp/v2/types/hra-ind"
}
],
"wp:attachment": [
{
"href": "http://wp-dev.test/wp-json/wp/v2/media?parent=71"
}
],
"curies": [
{
"name": "wp",
"href": "https://api.w.org/{rel}",
"templated": true
}
]

Where this slug is matched. It works.

If I do with this URL

http://wp-dev.test/wp-json/wp/v2/hra-ind?crb_individual_id=sj57968

It returned all posts, not matched "SJ57968" for crb_individual_id, in other words it did not work. How to fix it with URL custom parameter such as "?crb_individual_id=" ?

0
jkhkhfkjsdhf 1 month 0 Answers 9 views 0

Leave an answer