JavaScript for WordPress › Forums › Gutenberg Development › Getting Taxonomy Selection to Work on Custom Post Feed
- This topic has 2 replies, 2 voices, and was last updated 6 years, 1 month ago by mengland.
-
AuthorPosts
-
October 8, 2018 at 7:18 pm #60844menglandParticipant
Hello,
I’m currently developing a post feed block that works with custom post types and taxonomies to display a post feed. I can get my custom post type to display in the editor and the taxonomies to appear in the category selector. However, if I select a taxonomy the post list in the editor does not change, which tells me it’s something with
latestPostsQuery
in the edit.js file. I’ve tried many combinations of query modifications but haven’t had any luck.I tried reaching out on the core editor slack, searched through Gutenberg Github, and have done a lot of googling without any luck. If anyone has any helpful information that could point out what I’m doing incorrectly I would be very grateful.
Here is my working files for this block, it’s based on the Latest Posts block.
CPT Post Feed Working FilesThanks,
October 8, 2018 at 9:24 pm #60871Zac GordonKeymasterI took a quick look at the code, but on the event handler for handling the selection of checkboxes can you at least get something to trigger so you know that part is working. For example log out what the new request is along with the modified query results.
Also can you mock it up to give you a custom query from the start by hardcoding it like one of the custom taxonomies have been selected.
Just thinking of a few ways to begin troubleshooting.
October 10, 2018 at 1:22 pm #61184menglandParticipantZac,
Thank you for the advice. Luckily all of the toggles and control panel settings worked perfectly before hand. So, I took your advice in a little bit different direction to try and narrow down what I could change in the query versus what didn’t work. I searched through the Gutenberg repo and didn’t find too many helpful bits that actually altered the query which led me to ask where the query keys and terms originated from. Long story short the answer involved referring to the Rest API Documentation.
When I looked at the term
categories
in the document it said “The terms assigned to the object in the category taxonomy”. I then addedhms_event_types: categories
to change the endpoint to match my taxonomy. Everything worked like a charm after that. Thecategories
constant returns an integer for the post id which fixed the post query displayed in the editor.Just wanted to share this bit of information in hopes that it might help save time.
Here is the updated version of my block
Event Custom Post Feed Block -
AuthorPosts
- You must be logged in to reply to this topic.