Troubleshooting

The troubleshooting documentation aims help you with common challenges you may face while using Conditional Blocks on your WordPress site.

What to do if your Post Type is not listed in settings

The plugin will automatically attempt to detect all available & Custom Post Types. If your CPT is not showing up, then it’s likely not supported within the WordPress REST API.

Don’t worry – The fix is easy if you hare using a plugin or code to register Post Types.

Look for the setting called “Show In REST” and enable it.

The setting will allow the post type to be visible within the WordPress Block Editor & Conditional Block.

If you are using a plugin, or these which controls the Post Types, then you can override the Post Type settings using a few snippets.

Overriding an exiting Post Type to enable REST API

In the below example the Custom Post Type ID is portfolio. The snippet will override the settings to enable the “Show in Rest” functionality.

/**
 * Enable REST API for a custom post type. In this example CPT is called portfolio.
 */

function cb_custom_enable_rest_for_custom_post_type($args, $post_type) {
    if ('portfolio' === $post_type) {
        $args['show_in_rest'] = true;
    }
    return $args;
}

add_filter('register_post_type_args', 'cb_custom_enable_rest_for_custom_post_type', 999, 2);Code language: PHP (php)

Overriding an existing Taxonomy to enable REST API

In the below example the taxonomy (also known as categories) has the ID of `project-type’. You should change this to your own taxonomy id.

Tags/attributes should be automatically enabled with the snippet as well.

function cb_custom_taxonomy_rest_args( $args, $taxonomy ) {
    if ( 'project-type' === $taxonomy || 'project-attributes' === $taxonomy) {
        $args['show_in_rest'] = true;
    }
    return $args;
}
add_filter( 'register_taxonomy_args', 'cb_custom_taxonomy_rest_args', 999, 2 );Code language: PHP (php)
Was this page helpful?