技术求助:PHP非数值值警告(nd-booking插件指定文件第133行)
Hey there, let's break down how to fix those "non-numeric value encountered" warnings from the ND Booking plugin. These errors almost always happen when the code tries to perform a numerical operation (like addition, multiplication, or comparison) on a value that isn't a number—think empty strings, null values, or text that can't be converted to a number.
Step 1: Inspect the problematic code line
First, let's look at line 133 in /wp-content/plugins/nd-booking/inc/shortcodes/include/search-results/nd_booking_post_preview-1.php. You can access this file via:
- FTP/SFTP (connect to your server and navigate to the path)
- WordPress Dashboard > Appearance > Theme File Editor (note: you might need to disable
DISALLOW_FILE_EDITinwp-config.phptemporarily if this is locked)
Chances are, the line looks something like this (example):
$total_price = $item_price * $booking_quantity;
In this case, either $item_price or $booking_quantity is holding a non-numeric value when the code runs.
Step 2: Trace where the non-numeric value comes from
Next, figure out what's feeding those variables:
- If the variables pull from custom post fields (like booking prices), check if all your booking items have valid numeric values (no empty fields, no text like "N/A").
- If they come from user input (like a search form), the plugin might not be validating that users enter numbers only, leading to non-numeric values being passed through.
- Sometimes, plugin settings might have default values set incorrectly (e.g., a blank field instead of 0).
Step 3: Fix the issue
Here are reliable ways to resolve the warning:
Option 1: Add numeric validation/conversion to the code
Modify line 133 (and related lines if needed) to ensure variables are always numeric before operations. For example:
// Convert values to floats (or integers, if you're dealing with whole numbers) $item_price = is_numeric($item_price) ? floatval($item_price) : 0; $booking_quantity = is_numeric($booking_quantity) ? intval($booking_quantity) : 1; // Now perform the calculation safely $total_price = $item_price * $booking_quantity;
This ensures even if the original value is non-numeric, it gets converted to a valid number (0 or 1 here) to avoid the warning.
⚠️ Note: If you edit the plugin file, make a backup first—plugin updates will overwrite your changes. Consider using a custom snippet if you want a more permanent fix that survives updates.
Option 2: Update the ND Booking plugin
This might be a known bug that the developer has fixed in a newer version. Head to WordPress Dashboard > Plugins, find ND Booking, and check for available updates. Install the latest version and see if the warnings disappear.
Option 3: Verify your booking content and settings
Go through your booking items and ensure all price/quantity fields have valid numeric values. Check plugin settings related to pricing or booking defaults to make sure no fields are left blank (set them to 0 if needed).
Option 4: Temporary warning suppression (not recommended)
If you need to hide the warnings immediately while troubleshooting, you can disable debug mode in wp-config.php:
define('WP_DEBUG', false); define('WP_DEBUG_DISPLAY', false);
This only hides the warning, not fixes the underlying issue—use this as a last resort.
Final Tip
If you're not comfortable editing code, reach out to the ND Booking plugin's support team with the exact warning details. They can provide an official fix or guide you further.
内容的提问来源于stack exchange,提问作者jesus ochoa

