Learn how to fix the common WordPress error related to invalid JSON responses when saving a page. We'll break down the solution for your custom code! --- This video is based on the question https://stackoverflow.com/q/65348999/ asked by the user 'user2107656' ( https://stackoverflow.com/u/2107656/ ) and on the answer https://stackoverflow.com/a/65349370/ provided by the user 'Zed' ( https://stackoverflow.com/u/2036858/ ) at 'Stack Overflow' website. Thanks to these great users and Stackexchange community for their contributions. Visit these links for original content and any more details, such as alternate solutions, latest updates/developments on topic, comments, revision history etc. For example, the original title of the Question was: $wpdb- get_results with variable Also, Content (except music) licensed under CC BY-SA https://meta.stackexchange.com/help/licensing The original Question post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/by-sa/4.0/ ) license, and the original Answer post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/by-sa/4.0/ ) license. If anything seems off to you, please feel free to write me at vlogize [AT] gmail [DOT] com. --- Resolving the Updating failed. The response is not a valid JSON response. Error in WordPress When working with custom WordPress functionalities, developers may encounter various errors. One particularly frustrating error is: "Updating failed. The response is not a valid JSON response." If you’ve faced this issue while saving a page after implementing a custom function, you’re in the right place. We will break down this problem and provide a clear solution. Understanding the Problem The problem occurs within your custom function designed to clear transients when saving a post. You implemented the following code: [[See Video to Reveal this Text or Code Snippet]] Analyzing the Error Upon saving a page, if the invalid JSON error appears, it indicates that something went wrong during the response generation. In this instance, it’s related to the SQL query where $post_id is being used. Specifically, the placement of single quotes around the variable appears to cause the issue. The Solution To resolve this error, you need to correct the string concatenation in the SQL query. Here's the revision you need to make: Corrected Code Example Replace your initial SQL code with the modified version below: [[See Video to Reveal this Text or Code Snippet]] Explanation of Changes: Single Quotes Positioning: The original code had single quotes improperly placed around the $post_id. Correcting their positions allows PHP to interpret the variable correctly as part of the string. String Concatenation: By integrating the variable directly into the string within the correct places, the SQL query now properly includes the $post_id values as intended. Conclusion With this simple adjustment, your custom function will be able to access the desired transient options without causing a JSON response error. Always double-check your string syntax when working with variables in SQL queries within WordPress. Feel free to apply these changes and verify if the initial error persists. Keeping your code clean and error-free not only enhances functionality but also improves user experience on your WordPress site! If you still experience issues or have further questions, don’t hesitate to reach out. Happy coding!

$wpdb- get_results with variablewordpress