Thread Starter
Cheryl
(@tricheryltops)
Well, I used the following and it worked to get the event post types and categories to show in Generate Blocks query loop:
/*add rest API support to event post type*/
add_filter( 'register_post_type_args', 'my_post_type_args', 10, 2 );
function my_post_type_args( $args, $post_type ) {
if ( 'event' === $post_type ) {
$args['show_in_rest'] = true;
// Optionally customize the rest_base or rest_controller_class
$args['rest_base'] = 'events';
$args['rest_controller_class'] = 'WP_REST_Posts_Controller';
}
return $args;
}
/**
* Add REST API support to an already registered taxonomy event category and tags.
*/
add_filter( 'register_taxonomy_args', 'my_taxonomy_args', 10, 2 );
function my_taxonomy_args( $args, $taxonomy_name ) {
if ( 'event-categories' === $taxonomy_name ) {
$args['show_in_rest'] = true;
// Optionally customize the rest_base or rest_controller_class
$args['rest_base'] = 'event-categories';
$args['rest_controller_class'] = 'WP_REST_Terms_Controller';
}
return $args;
}
Now I need to figure out how to add event tags to that without causing an error:)
The block editor (Rest API) can be enabled for event, recurring-event and location post types by setting the EM_GUTENBERG constant to true.
define( 'EM_GUTENBERG', true );
This doesn’t appear to enable for event-tags or event-categories taxonomies.
The plugin provides filter hooks for event taxonomies.
apply_filters( 'em_ct_tags', array $args );
apply_filters( 'em_ct_categories', array $args );
Usage
if ( defined( 'EM_GUTENBERG' ) && EM_GUTENBERG ) {
add_filter( 'em_ct_tags', 'enable_block_editor' );
add_filter( 'em_ct_categories', 'enable_block_editor' );
}
/**
* Enable Rest API for Event Taxonomies
*
* @param array $args
* @return array $args modified array
*/
function enable_block_editor( $args ) {
$args['show_in_rest'] = true;
return $args;
}