Error 400 when adding or removing terms

Support General Error 400 when adding or removing terms

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #39000
    ArnoArno
    Participant

    Hi,

    If I create a new post and add taxonomy terms, the browser console shows a lot of 400 errors on the POST request to /wp-json/wp/v2/taxonomyname?_locale=user.

    The terms do get added to the post successfully.

    This happens on WordPress 6.0 and 6.1. I have disabled all plugins except Meta Box, and I'm on the 2023 theme.

    Sometimes, when I have added terms to the meta box, and then remove a lot of them, it will also cause these 400 errors. But even more in this case. It seems to be stuck in a loop for a minute or two. The website gets unresponsive in that case.

    I have a test site to log into if needed.

    Kind regards,
    Arno

    #39055
    PeterPeter
    Moderator

    Hello Arno,

    Please generate the PHP code from the builder and add the code to the file functions.php in the theme/child theme folder to create the custom taxonomy and deactivate all plugins (including Meta Box plugins) and recheck this issue. Let me know if the issue is resolved.

    #39060
    ArnoArno
    Participant

    Hi Peter,

    I first deleted all taxonomies and post types not needed for the test. Then I generated the PHP code for 1 remaining post type and 2 remaining taxonomies. That code did not seem correct: it still referred to trashed post types and taxonomies. Does the code generator not check for that?

    I tried to correct the code, here what I have:

    add_action( 'init', 'your_prefix_register_post_type' );
    function your_prefix_register_post_type() {
    	$labels = [
    		'name'                     => esc_html__( 'Activities', 'your-textdomain' ),
    		'singular_name'            => esc_html__( 'Activity', 'your-textdomain' ),
    		'add_new'                  => esc_html__( 'Add New', 'your-textdomain' ),
    		'add_new_item'             => esc_html__( 'Add new activity', 'your-textdomain' ),
    		'edit_item'                => esc_html__( 'Edit Activity', 'your-textdomain' ),
    		'new_item'                 => esc_html__( 'New Activity', 'your-textdomain' ),
    		'view_item'                => esc_html__( 'View Activity', 'your-textdomain' ),
    		'view_items'               => esc_html__( 'View Activities', 'your-textdomain' ),
    		'search_items'             => esc_html__( 'Search Activities', 'your-textdomain' ),
    		'not_found'                => esc_html__( 'No activities found', 'your-textdomain' ),
    		'not_found_in_trash'       => esc_html__( 'No activities found in Trash', 'your-textdomain' ),
    		'parent_item_colon'        => esc_html__( 'Parent Activity:', 'your-textdomain' ),
    		'all_items'                => esc_html__( 'All Activities', 'your-textdomain' ),
    		'archives'                 => esc_html__( 'Activity Archives', 'your-textdomain' ),
    		'attributes'               => esc_html__( 'Activity Attributes', 'your-textdomain' ),
    		'insert_into_item'         => esc_html__( 'Insert into activity', 'your-textdomain' ),
    		'uploaded_to_this_item'    => esc_html__( 'Uploaded to this activity', 'your-textdomain' ),
    		'featured_image'           => esc_html__( 'Featured image', 'your-textdomain' ),
    		'set_featured_image'       => esc_html__( 'Set featured image', 'your-textdomain' ),
    		'remove_featured_image'    => esc_html__( 'Remove featured image', 'your-textdomain' ),
    		'use_featured_image'       => esc_html__( 'Use as featured image', 'your-textdomain' ),
    		'menu_name'                => esc_html__( 'Activities', 'your-textdomain' ),
    		'filter_items_list'        => esc_html__( 'Filter activities list', 'your-textdomain' ),
    		'filter_by_date'           => esc_html__( '', 'your-textdomain' ),
    		'items_list_navigation'    => esc_html__( 'Activities list navigation', 'your-textdomain' ),
    		'items_list'               => esc_html__( 'Activities list', 'your-textdomain' ),
    		'item_published'           => esc_html__( 'Activity published', 'your-textdomain' ),
    		'item_published_privately' => esc_html__( 'Activity published privately', 'your-textdomain' ),
    		'item_reverted_to_draft'   => esc_html__( 'Activity reverted to draft', 'your-textdomain' ),
    		'item_scheduled'           => esc_html__( 'Activity scheduled', 'your-textdomain' ),
    		'item_updated'             => esc_html__( 'Activity updated', 'your-textdomain' ),
    	];
    	$args = [
    		'label'               => esc_html__( 'Activities', 'your-textdomain' ),
    		'labels'              => $labels,
    		'description'         => '',
    		'public'              => true,
    		'hierarchical'        => false,
    		'exclude_from_search' => false,
    		'publicly_queryable'  => true,
    		'show_ui'             => true,
    		'show_in_nav_menus'   => true,
    		'show_in_admin_bar'   => true,
    		'show_in_rest'        => true,
    		'query_var'           => true,
    		'can_export'          => true,
    		'delete_with_user'    => false,
    		'has_archive'         => true,
    		'rest_base'           => '',
    		'show_in_menu'        => true,
    		'menu_position'       => 2,
    		'menu_icon'           => 'dashicons-camera-alt',
    		'capability_type'     => 'post',
    		'supports'            => ['title', 'editor', 'thumbnail', 'excerpt', 'author', 'custom-fields', 'revisions'],
    		'taxonomies'          => ['season', 'best-season'],
    		'rewrite'             => [
    			'with_front' => false,
    		],
    	];
    
    	register_post_type( 'activity', $args );
    }
    
    add_action( 'init', 'undefined' );
    function undefined() {
    	$labels = [
    		'name'                       => esc_html__( 'Seasons', 'your-textdomain' ),
    		'singular_name'              => esc_html__( 'Season', 'your-textdomain' ),
    		'search_items'               => esc_html__( 'Search Seasons', 'your-textdomain' ),
    		'popular_items'              => esc_html__( 'Popular Seasons', 'your-textdomain' ),
    		'all_items'                  => esc_html__( 'All Seasons', 'your-textdomain' ),
    		'parent_item'                => esc_html__( 'Parent Season', 'your-textdomain' ),
    		'parent_item_colon'          => esc_html__( 'Parent Season:', 'your-textdomain' ),
    		'edit_item'                  => esc_html__( 'Edit Season', 'your-textdomain' ),
    		'update_item'                => esc_html__( 'Update Season', 'your-textdomain' ),
    		'add_new_item'               => esc_html__( 'Add New Season', 'your-textdomain' ),
    		'new_item_name'              => esc_html__( 'New Season Name', 'your-textdomain' ),
    		'separate_items_with_commas' => esc_html__( 'Separate Seasons with commas', 'your-textdomain' ),
    		'add_or_remove_items'        => esc_html__( 'Add or remove Seasons', 'your-textdomain' ),
    		'choose_from_most_used'      => esc_html__( 'Choose from the most used Seasons', 'your-textdomain' ),
    		'menu_name'                  => esc_html__( 'Seasons', 'your-textdomain' ),
    		'view_item'                  => esc_html__( 'View Season', 'your-textdomain' ),
    		'filter_by_item'             => esc_html__( 'Filter by Season', 'your-textdomain' ),
    		'not_found'                  => esc_html__( 'Not Seasons found', 'your-textdomain' ),
    		'no_terms'                   => esc_html__( 'No Seasons', 'your-textdomain' ),
    		'items_list_navigation'      => esc_html__( 'Seasons list navigation', 'your-textdomain' ),
    		'items_list'                 => esc_html__( 'Seasons list', 'your-textdomain' ),
    		'back_to_items'              => esc_html__( 'Back to Seasons', 'your-textdomain' ),
    	];
    	$args = [
    		'label'                 => esc_html__( '', 'undefined' ),
    		'labels'                => $labels,
    		'description'           => '',
    		'wpcf-tax'              => season,
    		'icon'                  => admin-post,
    		'public'                => public,
    		'hierarchical'          => false,
    		'supports'              => [object Object],
    		'show_ui'               => true,
    		'query_var_enabled'     => true,
    		'query_var'             => true,
    		'update_count_callback' => '',
    		'_toolset_edit_last'    => 1649086927,
    		'_wpcf_author_id'       => 1,
    		'name'                  => false,
    		'show_in_rest'          => true,
    		'publicly_queryable'    => true,
    		'meta_box_cb'           => 'post_tags_meta_box',
    		'rest_base'             => '',
    		'rewrite'               => [
    			'with_front'   => true,
    			'hierarchical' => false,
    		],
    	];
    	register_taxonomy( 'seasons', ['activity'], $args );
    }
    
    add_action( 'init', 'undefined' );
    function undefined() {
    	$labels = [
    		'name'                       => esc_html__( 'Best seasons', 'your-textdomain' ),
    		'singular_name'              => esc_html__( 'Best season', 'your-textdomain' ),
    		'search_items'               => esc_html__( 'Search Best seasons', 'your-textdomain' ),
    		'popular_items'              => esc_html__( 'Popular Best seasons', 'your-textdomain' ),
    		'all_items'                  => esc_html__( 'All Best seasons', 'your-textdomain' ),
    		'parent_item'                => esc_html__( 'Parent Best season', 'your-textdomain' ),
    		'parent_item_colon'          => esc_html__( 'Parent Best season:', 'your-textdomain' ),
    		'edit_item'                  => esc_html__( 'Edit Best season', 'your-textdomain' ),
    		'update_item'                => esc_html__( 'Update Best season', 'your-textdomain' ),
    		'add_new_item'               => esc_html__( 'Add New Best season', 'your-textdomain' ),
    		'new_item_name'              => esc_html__( 'New Best season Name', 'your-textdomain' ),
    		'separate_items_with_commas' => esc_html__( 'Separate Best seasons with commas', 'your-textdomain' ),
    		'add_or_remove_items'        => esc_html__( 'Add or remove Best seasons', 'your-textdomain' ),
    		'choose_from_most_used'      => esc_html__( 'Choose from the most used Best seasons', 'your-textdomain' ),
    		'menu_name'                  => esc_html__( 'Best seasons', 'your-textdomain' ),
    		'view_item'                  => esc_html__( 'View Best season', 'your-textdomain' ),
    		'filter_by_item'             => esc_html__( 'Filter by Best season', 'your-textdomain' ),
    		'not_found'                  => esc_html__( 'Not Best seasons found', 'your-textdomain' ),
    		'no_terms'                   => esc_html__( 'No Best seasons', 'your-textdomain' ),
    		'items_list_navigation'      => esc_html__( 'Best seasons list navigation', 'your-textdomain' ),
    		'items_list'                 => esc_html__( 'Best seasons list', 'your-textdomain' ),
    		'back_to_items'              => esc_html__( 'Back to Best seasons', 'your-textdomain' ),
    	];
    	$args = [
    		'label'                 => esc_html__( '', 'undefined' ),
    		'labels'                => $labels,
    		'description'           => '',
    		'wpcf-tax'              => best-season,
    		'icon'                  => admin-post,
    		'public'                => public,
    		'hierarchical'          => false,
    		'supports'              => [object Object],
    		'show_ui'               => true,
    		'query_var_enabled'     => true,
    		'query_var'             => true,
    		'update_count_callback' => '',
    		'_toolset_edit_last'    => 1649086947,
    		'_wpcf_author_id'       => 1,
    		'name'                  => false,
    		'show_in_rest'          => true,
    		'publicly_queryable'    => true,
    		'meta_box_cb'           => 'post_tags_meta_box',
    		'rest_base'             => '',
    		'rewrite'               => [
    			'with_front'   => true,
    			'hierarchical' => false,
    		],
    	];
    	register_taxonomy( 'best-seasons', ['activity'], $args );
    }

    This throws an error:
    Parse error: syntax error, unexpected token "public" in /public_html/testsite/wp-content/themes/kadence_child/functions.php on line 113

    What's wrong with the code?

    Thanks,
    Arno

    #39076
    PeterPeter
    Moderator

    The argument public should be set to true or false. You can create a test taxonomy with the tool Online Generator and combine it with your code https://metabox.io/taxonomy-generator/

    #39090
    ArnoArno
    Participant

    I tried but I keep getting critical errors.

    It's taking too much time. I removed the code. I will e-mail you the login to the test site. Please have a look. Thanks!

    #39110
    PeterPeter
    Moderator

    I don't see the error 400 on my end when trying to add some terms Best Season to a post, screen record https://monosnap.com/file/kAw6x5Xk3FOQpLQ0wbVW9fPuTdOpRz

    #39120
    ArnoArno
    Participant

    Hi Peter,

    I tested in another browser now: Firefox with the cache emptied, instead of Chrome before. But it's still a problem, so it\s not browser dependent.

    I will e-mail you a link to my screen recording. Perhaps you can see what I do different than you.

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.