Pregunta

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

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
scroll top