Updating a custom post type’s custom taxonomy in a custom editor block

I’m really struggling trying to get any information at all on how to do this. the project is part of a church website holding a collection of ‘talks’ (custom post type) which has data attached such as AudioURL, VideoURL, Speaker, Series etc. Speaker and Series are custom taxonomies rather than free text.

The aim is to allow someone who doesn’t understand the structure to be able to add posts, and so all required data is entered via a custom block on the edit screen. Much of this has been acheived whether stored as WordPress data (e.g. Title, slug) or custom fields, and I can get the complete list of taxonomy terms to populate a SelectControl of ComboboxControl.

What is missing is being able to get the current value of the post’s taxonomy term, and being able to set it. I’m pretty sure I need to use GetEntityRecords and EditEntityRecords, but I can’t find any useful documentation or examples.

Can anyone tell me how it is done?

For setting it, I have tried

function updateSeriesValue( newValue ) {
            wp.data.dispatch( 'core' ).editEntityRecord( 'post_type', 'talks', post_id, { 'series': [ newValue ] } );
        };

which gives me the error: Uncaught (in promise) Error: The entity being edited (post_type, talks) does not have a loaded config.

For reading the value, I’ve tried

wp.data.select('core').getEntityRecords('post_type','talks',post_id,'series');

but I’m pretty sure that is wrong.

Thanks in advance

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

I gave up and went for a php solution. The code in the custom block uses and updates a meta field, then I use the ‘updated_post_meta’ hook to set the taxonomy term from the meta field. Before editing I use the ‘the_post’ hook to set the meta value from the taxonomy term.

A bit clunky, but it works.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x