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
editEntityRecord
edits the original entity, so your first attempt does not set the working copy of the posts terms, but rather it attempts to edit the term itself directly on the website via the API.getEditedPostAttribute
oreditPost
? Modifying entity records isn't the same as checking the term box in the editor UI, it's the same as editing the term on the category admin page. The solution should be very very similar to what the tutorials about setting post meta look like