Support Forum
Support › Meta Box Builder › Critical error after custom fields set to display on custom post type
I created a Job(job) post type. I created a custom fields group, 'Job listing information'. It uses some taxonomies, and I set up the custom post type to support these taxonomies.
Under the custom fields group settings I selected to display the custom fields group on the 'Post type': 'Job(job)'.
However, when I go to the Job custom post type in the WP Dashboard and I click on Add new Job, I get this message:
"There has been a critical error on this website. Please check your site admin email inbox for instructions. If you continue to have problems, please try the support forums.
Learn more about troubleshooting WordPress."
I have no other plug-ins installed on my site, just Meta Box and Meta Box AIO. I have run WP-optimize and cleaned up my database.
If I go to the custom fields group settings tab and select the custom fields group to NOT display the custom fields group on the 'Post type': 'Job(job)', but to nothing, I can go to the Job custom post type and click on 'Add new job', that works fine (but of course I now do not have all the custom fields I created showing beneath it.
If I go back to the custom fields group settings again and now make it show on 'Post type': 'Post(post)', the same Critical error issue appears for WP's default Post post type. What is going on here?
I am thinking... I did have to increase the max_input_vars before to be able to finish my custom fields group - it is pretty large. Could it be so that I need to change some other limit to have the custom fields group be able to show when adding a post?
Thanks for your support...
ps: I did also make a separate page, and added a Meta Box block user submission form to it, so that the custom fields group shows as a front-end user submission form. That all works nicely, so it is not an issue with the custom fields group.
I had this before with another post type, which I deleted completely, and so the above describes the process happening after having already cleaned up and tried again with a new custom post type.
I've been able to produce a debug.log:
[22-Jan-2025 15:18:50 UTC] PHP Fatal error: Uncaught TypeError: str_contains(): Argument #1 ($haystack) must be of type string, array given in /home/u412395423/domains/mydomain.com/public_html/wp-content/plugins/meta-box-aio/vendor/meta-box/text-limiter/text-limiter.php:85
Stack trace:
#0 /home/u412395423/domains/mydomain.com/public_html/wp-content/plugins/meta-box-aio/vendor/meta-box/text-limiter/text-limiter.php(85): str_contains()
#1 /home/u412395423/domains/mydomain.com/public_html/wp-includes/class-wp-hook.php(326): MB_Text_Limiter->get_value()
#2 /home/u412395423/domains/mydomain.com/public_html/wp-includes/plugin.php(205): WP_Hook->apply_filters()
#3 /home/u412395423/domains/mydomain.com/public_html/wp-content/plugins/meta-box/inc/functions.php(162): apply_filters()
#4 /home/u412395423/domains/mydomain.com/public_html/wp-content/plugins/meta-box-aio/vendor/meta-box/mb-rest-api/src/Base.php(64): rwmb_get_value()
#5 /home/u412395423/domains/mydomain.com/public_html/wp-content/plugins/meta-box-aio/vendor/meta-box/mb-rest-api/src/Base.php(49): MetaBox\RestApi\Base->get_values()
#6 /home/u412395423/domains/mydomain.com/public_html/wp-includes/rest-api/endpoints/class-wp-rest-controller.php(439): MetaBox\RestApi\Base->get()
#7 /home/u412395423/domains/mydomain.com/public_html/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php(2070): WP_REST_Controller->add_additional_fields_to_object()
#8 /home/u412395423/domains/mydomain.com/public_html/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php(635): WP_REST_Posts_Controller->prepare_item_for_response()
#9 /home/u412395423/domains/mydomain.com/public_html/wp-includes/rest-api/class-wp-rest-server.php(1292): WP_REST_Posts_Controller->get_item()
#10 /home/u412395423/domains/mydomain.com/public_html/wp-includes/rest-api/class-wp-rest-server.php(1125): WP_REST_Server->respond_to_request()
#11 /home/u412395423/domains/mydomain.com/public_html/wp-includes/rest-api.php(576): WP_REST_Server->dispatch()
#12 /home/u412395423/domains/mydomain.com/public_html/wp-includes/rest-api.php(2957): rest_do_request()
#13 [internal function]: rest_preload_api_request()
#14 /home/u412395423/domains/mydomain.com/public_html/wp-includes/block-editor.php(756): array_reduce()
#15 /home/u412395423/domains/mydomain.com/public_html/wp-admin/edit-form-blocks.php(77): block_editor_rest_api_preload()
#16 /home/u412395423/domains/mydomain.com/public_html/wp-admin/post-new.php(72): require('/home/u25520214...')
#17 {main}
thrown in /home/u412395423/domains/mydomain.com/public_html/wp-content/plugins/meta-box-aio/vendor/meta-box/text-limiter/text-limiter.php on line 85
* just shielded my domain name and database number
My text-limiter extension was on, and when turning it off the error disappears...
I deleted all form fields until i reached the one that gave me problems.
It is a WYSIWYG field type. This field is both cloneable, as well as text-limited.
This combination of text limitation and cloneable is causing a problem.
I verified this in 2 ways:
1) When I go to this specific form field and under 'general settings' > 'text limiter' I delete the max word count so that it is left blank (or has a 0), there is no problem. The form fields group now correctly loads when I click 'add new job'. But As soon as I put the text-limiter on and the field remains cloneable, boom: the critical error appears instead of the add new screen where I can add/edit the post.
2) I made a new form fields group and made it to show on the 'Post type': 'Post(post)'. That is the default wordpress post post type.
There are no fields yet.
When I now add a form field type WYSIWYG there is no problem. Clicking the 'add a new post' does not at this moment produce the same critical error.
If I now add a text-limiter, say 45 words, and I now press 'add new post', still no critical error.
If I now make it cloneable, boom: the critical error shows. I have not done anything special to this wysiwyg field.
the same behaviour shows with the text area form field type.
Add a field of the text area field type > no error. Limit the text > no error. Make it cloneable: produces the error.
Same applies to regular text form field type.
Add a field of the text field type > no error. Limit the text > no error. Make it cloneable: produces the error.
This can't be just me? Can you please try to reproduce this error, Peter or someone at Meta Box?
I can't hardly believe this is just me. At the same time, this behaviour is not described in the Text-limiter extension documention here (https://metabox.io/plugins/meta-box-text-limiter/) or here (https://docs.metabox.io/extensions/meta-box-text-limiter/) but then again, this documentation also does not say the text-limiter is compatible with the WYSIWYG field type although it is.
Please verify this is an issue with metabox and please fix ASAP if it is - i need this cloneable, text-limited WYSIWYG field (and if needed for a temporary fall-back, a text area/text field type would work too. But they are not working either
Hello John,
Thank you for your feedback. I can reproduce the issue on my demo site and it looks related to PHP 8.0 or later version. You can try to downgrade PHP to 7.4 and recheck the issue.
Hi Peter! Switching to PHP version 7.4 did solve this particular problem. Thanks for this! However, I can't really say this solution is viable, as I must use a more recent PHP version for security and performance reasons. 7.4 on the other hand End of Life since Nov '22 and increases risks of security vulnerabilities, performance degradation, and application instability.
My request is therefore if you can aks MB's developers to update this functionality to work with the more recent PHP versions? Version 8 came out in Nov '20, 8.1 in Nov '21, 8.2 in Dec '22, 8.3 in Nov '23 and 8.4 just recently (although I understand that the latest version is too recent for many people). I hope your team is able to make Meta Box fully compatible with PHP 8 at the minimum, and so I can use this particular functionality again.
I will have to stick to PHP 8 and so will have to deactivate the text-limiter function although that is an important reason for why I went for Meta Box. I am afraid to run into more PHP 8 issues :s.
Please let me know if your developers will pick this up.
Thanks so much for your presence, Peter. You are helping a ton!