I have two custom post types setup on my website. When I navigate to Custom Post Type Name > Add New Post Type in the WordPress admin panel, the following error is displayed via Cloudflare: Error code 502 Bad Gateway. I do not receive this error when creating new posts using the default post editor.
I have included the custom post type registration code below for reference. Other than creating a new post type, the functionality seems to be error free. Both affected custom post types utilize the same code for registration.
function theme_name_register_notice_post_type() {
$labels = array(
'name' => __( 'Notices', 'theme_name' ),
'singular_name' => __( 'Notice', 'theme_name' ),
'add_new' => __( 'Add New Notice', 'theme_name' ),
'add_new_item' => __( 'Add New Notice', 'theme_name' ),
'edit_item' => __( 'Edit Notice', 'theme_name' ),
'new_item' => __( 'New Notice', 'theme_name' ),
'view_item' => __( 'View Notice', 'theme_name' ),
'view_items' => __( 'View Notices', 'theme_name' ),
'search_items' => __( 'Search Notices', 'theme_name' ),
'not_found' => __( 'No notices found.', 'theme_name' ),
'not_found_in_trash' => __( 'No notices found in trash.', 'theme_name' ),
'parent_item_colon' => __( 'Parent Notices:', 'theme_name' ),
'all_items' => __( 'All Notices', 'theme_name' ),
'archives' => __( 'Notice Archives', 'theme_name' ),
'attributes' => __( 'Notice Attributes', 'theme_name' ),
'insert_into_item' => __( 'Insert into notice', 'theme_name' ),
'uploaded_to_this_item' => __( 'Uploaded to this notice', 'theme_name' ),
'featured_image' => __( 'Featured Image', 'theme_name' ),
'set_featured_image' => __( 'Set featured image', 'theme_name' ),
'remove_featured_image' => __( 'Remove featured image', 'theme_name' ),
'use_featured_image' => __( 'Use as featured image', 'theme_name' ),
'menu_name' => __( 'Notices', 'theme_name' ),
'filter_items_list' => __( 'Filter document list', 'theme_name' ),
'filter_by_date' => __( 'Filter by date', 'theme_name' ),
'items_list_navigation' => __( 'Notices list navigation', 'theme_name' ),
'items_list' => __( 'Notices list', 'theme_name' ),
'item_published' => __( 'Notice published.', 'theme_name' ),
'item_published_privately' => __( 'Notice published privately.', 'theme_name' ),
'item_reverted_to_draft' => __( 'Notice reverted to draft.', 'theme_name' ),
'item_scheduled' => __( 'Notice scheduled.', 'theme_name' ),
'item_updated' => __( 'Notice updated.', 'theme_name' ),
'item_link' => __( 'Notice Link', 'theme_name' ),
'item_link_description' => __( 'A link to an notice.', 'theme_name' ),
);
$args = array(
'labels' => $labels,
'description' => __( 'Current and past notices from your RM, Sask Alert, and other sources.', 'theme_name' ),
'public' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => false,
'show_in_rest' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-megaphone',
'capability_type' => 'post',
'capabilities' => array(),
'supports' => array( 'title', 'editor', 'revisions', 'custom-fields', 'author', 'thumbnail' ),
'taxonomies' => array( 'notice-type' ),
'has_archive' => true,
'rewrite' => array( 'slug' => 'notices', 'with_front' => false, ),
'can_export' => true,
'delete_with_user' => false,
'template' => array(),
'template_lock' => false,
);
register_post_type( 'notice', $args );
}
add_action( 'init', 'theme_name_register_notice_post_type' );
Each custom post type has its own custom taxonomy as well. The taxonomy code is below for reference.
function theme_name_register_taxonomy_notice_type() {
$labels = array(
'name' => _x( 'Notice Type', 'taxonomy general name' ),
'singular_name' => _x( 'Notice Type', 'taxonomy singular name' ),
'search_items' => __( 'Search Notice Types' ),
'all_items' => __( 'All Notice Types' ),
'parent_item' => __( 'Parent Notice Type' ),
'parent_item_colon' => __( 'Parent Notice Type:' ),
'edit_item' => __( 'Edit Notice Type' ),
'update_item' => __( 'Update Notice Type' ),
'add_new_item' => __( 'Add New Notice Type' ),
'new_item_name' => __( 'New Notice Type Name' ),
'menu_name' => __( 'Notice Types' ),
);
$args = array(
'labels' => $labels,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_rest' => true,
'show_tagcloud' => false,
'hierarchical' => true,
'rewrite' => array( 'slug' => 'notice-type', 'hierarchical' => true, ),
);
register_taxonomy( 'notice-type', [ 'notice' ], $args );
}
I have created two dashboard widgets that have quick links to creating new custom post types. The code generates quick link buttons that presets the category from the custom post type's taxonomy. These links load the editor with no errors. I have included the quick link code below for reference.
function theme_name_post_notices( $post ) {
$post_type = 'notice';
$taxonomy_name = 'notice-type'; // Notices taxonomy name
$terms = theme_name_get_terms_by_taxonomy_name( $taxonomy_name );
?>
<div class="os-dashboard-widget">
<p>
<?php esc_html_e( 'Use these links to post notices.', 'theme_name' ); ?>
</p>
<?php if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) : ?>
<ul class="os-content-grid">
<?php foreach ( $terms as $term ) : ?>
<li>
<a href="<?php echo esc_url( admin_url( 'post-new.php?post_type=' . $post_type . '&preset_term=' . $term->term_id ) ); ?>" class="button button--os-primary">
<?php echo esc_html( $term->name ); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
<?php
}
The server is nginx with PHP 8.2.26/FPM installed. The PHP memory limit is set to 512 megabytes. The PHP time limit and max input time are both set to 60.
No other areas of the admin panel are being affected by 502 bad gateway errors.
These errors only occur when the custom post types have custom taxonomies created and in use. I can test this because the site is multisite and some of the sites do not have the custom taxonomies populated.
Any ideas on why this is occurring?
I have two custom post types setup on my website. When I navigate to Custom Post Type Name > Add New Post Type in the WordPress admin panel, the following error is displayed via Cloudflare: Error code 502 Bad Gateway. I do not receive this error when creating new posts using the default post editor.
I have included the custom post type registration code below for reference. Other than creating a new post type, the functionality seems to be error free. Both affected custom post types utilize the same code for registration.
function theme_name_register_notice_post_type() {
$labels = array(
'name' => __( 'Notices', 'theme_name' ),
'singular_name' => __( 'Notice', 'theme_name' ),
'add_new' => __( 'Add New Notice', 'theme_name' ),
'add_new_item' => __( 'Add New Notice', 'theme_name' ),
'edit_item' => __( 'Edit Notice', 'theme_name' ),
'new_item' => __( 'New Notice', 'theme_name' ),
'view_item' => __( 'View Notice', 'theme_name' ),
'view_items' => __( 'View Notices', 'theme_name' ),
'search_items' => __( 'Search Notices', 'theme_name' ),
'not_found' => __( 'No notices found.', 'theme_name' ),
'not_found_in_trash' => __( 'No notices found in trash.', 'theme_name' ),
'parent_item_colon' => __( 'Parent Notices:', 'theme_name' ),
'all_items' => __( 'All Notices', 'theme_name' ),
'archives' => __( 'Notice Archives', 'theme_name' ),
'attributes' => __( 'Notice Attributes', 'theme_name' ),
'insert_into_item' => __( 'Insert into notice', 'theme_name' ),
'uploaded_to_this_item' => __( 'Uploaded to this notice', 'theme_name' ),
'featured_image' => __( 'Featured Image', 'theme_name' ),
'set_featured_image' => __( 'Set featured image', 'theme_name' ),
'remove_featured_image' => __( 'Remove featured image', 'theme_name' ),
'use_featured_image' => __( 'Use as featured image', 'theme_name' ),
'menu_name' => __( 'Notices', 'theme_name' ),
'filter_items_list' => __( 'Filter document list', 'theme_name' ),
'filter_by_date' => __( 'Filter by date', 'theme_name' ),
'items_list_navigation' => __( 'Notices list navigation', 'theme_name' ),
'items_list' => __( 'Notices list', 'theme_name' ),
'item_published' => __( 'Notice published.', 'theme_name' ),
'item_published_privately' => __( 'Notice published privately.', 'theme_name' ),
'item_reverted_to_draft' => __( 'Notice reverted to draft.', 'theme_name' ),
'item_scheduled' => __( 'Notice scheduled.', 'theme_name' ),
'item_updated' => __( 'Notice updated.', 'theme_name' ),
'item_link' => __( 'Notice Link', 'theme_name' ),
'item_link_description' => __( 'A link to an notice.', 'theme_name' ),
);
$args = array(
'labels' => $labels,
'description' => __( 'Current and past notices from your RM, Sask Alert, and other sources.', 'theme_name' ),
'public' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => false,
'show_in_rest' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-megaphone',
'capability_type' => 'post',
'capabilities' => array(),
'supports' => array( 'title', 'editor', 'revisions', 'custom-fields', 'author', 'thumbnail' ),
'taxonomies' => array( 'notice-type' ),
'has_archive' => true,
'rewrite' => array( 'slug' => 'notices', 'with_front' => false, ),
'can_export' => true,
'delete_with_user' => false,
'template' => array(),
'template_lock' => false,
);
register_post_type( 'notice', $args );
}
add_action( 'init', 'theme_name_register_notice_post_type' );
Each custom post type has its own custom taxonomy as well. The taxonomy code is below for reference.
function theme_name_register_taxonomy_notice_type() {
$labels = array(
'name' => _x( 'Notice Type', 'taxonomy general name' ),
'singular_name' => _x( 'Notice Type', 'taxonomy singular name' ),
'search_items' => __( 'Search Notice Types' ),
'all_items' => __( 'All Notice Types' ),
'parent_item' => __( 'Parent Notice Type' ),
'parent_item_colon' => __( 'Parent Notice Type:' ),
'edit_item' => __( 'Edit Notice Type' ),
'update_item' => __( 'Update Notice Type' ),
'add_new_item' => __( 'Add New Notice Type' ),
'new_item_name' => __( 'New Notice Type Name' ),
'menu_name' => __( 'Notice Types' ),
);
$args = array(
'labels' => $labels,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_rest' => true,
'show_tagcloud' => false,
'hierarchical' => true,
'rewrite' => array( 'slug' => 'notice-type', 'hierarchical' => true, ),
);
register_taxonomy( 'notice-type', [ 'notice' ], $args );
}
I have created two dashboard widgets that have quick links to creating new custom post types. The code generates quick link buttons that presets the category from the custom post type's taxonomy. These links load the editor with no errors. I have included the quick link code below for reference.
function theme_name_post_notices( $post ) {
$post_type = 'notice';
$taxonomy_name = 'notice-type'; // Notices taxonomy name
$terms = theme_name_get_terms_by_taxonomy_name( $taxonomy_name );
?>
<div class="os-dashboard-widget">
<p>
<?php esc_html_e( 'Use these links to post notices.', 'theme_name' ); ?>
</p>
<?php if ( ! empty( $terms ) && ! is_wp_error( $terms ) ) : ?>
<ul class="os-content-grid">
<?php foreach ( $terms as $term ) : ?>
<li>
<a href="<?php echo esc_url( admin_url( 'post-new.php?post_type=' . $post_type . '&preset_term=' . $term->term_id ) ); ?>" class="button button--os-primary">
<?php echo esc_html( $term->name ); ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
<?php
}
The server is nginx with PHP 8.2.26/FPM installed. The PHP memory limit is set to 512 megabytes. The PHP time limit and max input time are both set to 60.
No other areas of the admin panel are being affected by 502 bad gateway errors.
These errors only occur when the custom post types have custom taxonomies created and in use. I can test this because the site is multisite and some of the sites do not have the custom taxonomies populated.
Any ideas on why this is occurring?
Share Improve this question asked Feb 6 at 1:11 Mike HermaryMike Hermary 2173 silver badges11 bronze badges1 Answer
Reset to default 1I did some further research and testing, and found the issue to be related to nginx and not WordPress itself. The following Stack Overflow post included some configuration adjustments for the site's config file that resolved the 502 bad gateway issues. My configuration file's client_max_body_size
was already set to 64M
.
Here are the nginx settings I adjusted to resolve the issue:
fastcgi_temp_file_write_size 10m;
fastcgi_busy_buffers_size 512k;
fastcgi_buffer_size 512k;
fastcgi_buffers 16 512k;