From the Codex page for $wpdb
:
The function [
$wpdb->query
] returns an integer corresponding to the number of rows affected/selected. If there is a MySQL error, the function will returnFALSE
.
So in order to display a success/failure message, it should be a simple matter:
$result = $wpdb->query( "
DELETE FROM $wpdb->posts
WHERE anything = 'whocares'
" );
if( FALSE === $result ) {
echo( "Failed!" );
} else {
echo( "Great success!" );
}
Related Posts:
- Delete post revisions on post publish
- Copyright info change in Theme Child PHP
- Add footer.php to WordPress child theme
- Is the regular ajax request method safe or I should use admin-ajax.php?
- Insert all post IDs in new database table
- PHP code inside shortcodes
- WSoD being caused by this piece of code
- How to check if a meta value has already been assigned to any user?
- $wpdb->wp_users returning empty value for
- Log in / Log Out Custom Button
- Multiple meta_key in one global $wpdb;
- Display Data in Table from External Database in WP using Shortcodes
- Issue with fetching mysql data and displaying results via shortcode in webpage
- How to use mysql LIKE with wpdb?
- making php value numeric
- SQL error with custom query
- Modify WooCommerce used to get all orders in dashboard
- Need help for some PHP code
- How to preload header logo image in WordPress? like what’s the code and where do I put it?
- How to put 2 php codes in functions.php without site crashing
- How can I display a query in a page?
- How to set up an auto delete post?
- how to create twitter card without plugin in wordpress website?
- wp_set_object_terms and arrays
- How to get the original price of the product in woocommerce?
- How to use WordPress (PHP) functions in AngularJS partials files?
- How to add 2 posts under another post? Formatting should be intact
- Logout and redirect using the WP Menu
- Check if current page is wp-admin
- Using PHP to toggle stylesheet and header image, set in cookie
- Nested shortCode functions in the functions.php file
- How to display posts of specific category using a custom Query in WordPress?
- How to speed up admin-ajax.php in wordpress
- My Own layout in WooCommerce pages [closed]
- How do I publish only one page to production after making changes on staging?
- Using Multiple Submit buttons to trigger customised php functions
- get current product name in functions.php
- Get WooCommerce product details and transfer them to a custom DB table
- What is a valid parent for get_terms()?
- How to style options page in dashboard?
- Calculating a large number of MYSQL queries as customshort codes, slow
- Why ajax doesn’t work on certain wordpress hooks?
- Print last modified date only on posts
- WordPress Quick Question . How to Get Parent Link in Submenu in My Code
- Is the “_s” on this `sprintf(__(‘Page %s’, ‘_s’), max($paged, $page))` just refer to a text domain?
- Exclude category
- Security for data obtained from the database
- Make Current/Active Page Number a Link (WP_LINK_PAGES)
- How to make modifications only to certain elements of an HTML string on the server-side?
- Custom Pagination is Broken
- Sidebar not appearing in footer, but it appears everywhere else!
- Co-Authors Plus: How do I get all authors with a query?
- Why i can’t get custom fields value or post ID via Ajax?
- List post by title length
- How to reference PHP in Javascript
- Fallback image URL if no featured image exists via a shortcode function
- form $_post action value gets truncated after it passes through two forms
- Deactivate a plugin on wp version
- Add row to custom database Table and delete all rows older than 1 day
- the_post_thumbnail issues
- Some problems calling a function into sprintf() inside functions.php template file [closed]
- WP insert post Redirect after function has executed
- Uncaught TypeError: extract(): Argument #1 ($array) must be of type array, null given
- Cannot find the php_ini configuration file to find my error log to see why my code is not working
- How to Send Pingbacks for all Posts in WordPress?
- HTML comment cause issue in functions.php script root
- Programmatically add a product to the cart and set price to zero when buying from certain category
- I want to show cart items number if any or nothing, simple CART text
- Exclude category from function – PHP
- Hide a specific category title from displaying on site
- WordPress mysql deos not work with php7
- WordPress Ajax filter: Create two loops for different output styles?
- Error inserting into custom table – Object of class wpdb could not be converted to string [closed]
- Handling form actions in WordPress
- Need help with AJAX login to call php in functions.php to handle redirects based on user cap (role)
- How to call a function from functions.php with ajax?
- Set user status to absent on WordPress
- Shortcode’s output to use as other shortcode’s parameter
- Displaying POST content with HTML tags and all
- PHP script to redirect traffic based on website accessed
- How to remove title tag with this filter
- Showing wordpress latest post thumbnails in slider with auto increment
- Add two or multiple functions in WordPress Post or Page
- My function echos only “array”
- Notify admin (by email) if post added with specific tag
- Retrieving specific images from Media Library
- Can’t put a hyperlink on Featured Post’s Image
- How to set max users to 17.000
- Limit Taxonomy Parents
- WordPress HTML Helper
- List sibling pages widget, exclude current page
- Display default WordPress login/registration form into a modal window
- How to add button to top of theme customizer?
- Pull GET parameter from URL in functions.php
- Send foreach $_post method to contact form 7 [closed]
- Options.php loop won’t show!
- Predefine Magazine Style Layouts
- a problem in class in class-wp-hook.php
- change title of page dynamically
- Custom plugin doesn’t show in admin menu – when code added, displays an empty page