Gutenberg: attributes for category not always containing slug / taxonomy
-
So I don’t know how to properly word this because I am only starting out learning Gutenberg but I am having trouble with the attributes that are passed from the Block Editor to PHP whenever more than one category is selected. This can best be viewed in the core/latest-posts block.
When adding more than one category to the “categories” field, the attributes that are passed along with the first element just vanish, maybe you can see it better in this example:
[ { "id": 14, "value": "Beitragskat" }, { "id": 1, "count": 12, "description": "", "link": "http://localhost/wordpress/index.php/category/allgemein/", "name": "Allgemein", "slug": "allgemein", "taxonomy": "category", "parent": 0, "meta": [], "_links": { "self": [ { "href": "http://localhost/wordpress/index.php/wp-json/wp/v2/categories/1" } ], "collection": [ { "href": "http://localhost/wordpress/index.php/wp-json/wp/v2/categories" } ], "about": [ { "href": "http://localhost/wordpress/index.php/wp-json/wp/v2/taxonomies/category" } ], "wp:post_type": [ { "href": "http://localhost/wordpress/index.php/wp-json/wp/v2/posts?categories=1" } ], "curies": [ { "name": "wp", "href": "https://api.w.org/{rel}", "templated": true } ] } } ]Here you can see, that the category with the id ’14’ now does not have all this extra information that the category with the id ‘1’ has. Also, when category ‘1’is deleted and only category ’14’ remains, after saving the attributes[‘categories’] look like this:
[ { "id": 14, "value": "Beitragskat" } ]When removing category ’14’ and re-adding it, the object now looks like this:
[ { "id": 14, "count": 1, "description": "", "link": "http://localhost/wordpress/index.php/category/beitragskat/", "name": "Beitragskat", "slug": "beitragskat", "taxonomy": "category", "parent": 0, "meta": [], "_links": { "self": [ { "href": "http://localhost/wordpress/index.php/wp-json/wp/v2/categories/14" } ], "collection": [ { "href": "http://localhost/wordpress/index.php/wp-json/wp/v2/categories" } ], "about": [ { "href": "http://localhost/wordpress/index.php/wp-json/wp/v2/taxonomies/category" } ], "wp:post_type": [ { "href": "http://localhost/wordpress/index.php/wp-json/wp/v2/posts?categories=14" } ], "curies": [ { "name": "wp", "href": "https://api.w.org/{rel}", "templated": true } ] } } ]This is not a problem in this block in particular, but I am trying to add a similar block based on a custom taxonomy and not being able to access all the other properties all the time comes in the way.
The topic ‘Gutenberg: attributes for category not always containing slug / taxonomy’ is closed to new replies.