The error you’re facing definitely isn’t coming from your code shown above. This is an error notice that was raised with WP 3.5 (IIRC) that should note that stand alone $wpdb->prepare( STATEMENT );
calls help nothing.
Missing argument 2 for wpdb::prepare()
tells you that you haven’t added any argument to the call. The prepare()
method works like sprintf()
aside from the fact that it only knows %s
for strings and %d
for digits.
So use it like this:
global $wpdb;
$wpdb->query( $wpdb->prepare(
"SELECT * FROM {$wpdb->posts} WHERE ID = %d AND post_type = %s",
abs_int( $_GET['post_id'] ),
esc_attr( $_GET['type' )
) );
Keep in mind that is just dummy code showing how to properly secure HTML form data processed in a WP DB call.
Related Posts:
- Should I use wpdb prepare?
- Is it mandatory to use $wpdb->prefix in custom tables
- $wpdb->insert_id
- Check for success of $wpdb->update() correctly
- WordPress and multithreading
- $wpdb->insert is changing a value
- Actions or filters fired when data is saved in a custom table
- Retrieving custom fields with $wpdb->get_results
- Really simple query giving error in SQL syntax
- Custom Plugin Database relations
- why creating tables using $wpdb is not being executed while installing plugins?
- How to use mysql IN statement with wpdb update method?
- Using $wpdb object in a widget
- Activation hook not creating table
- $wpdb -> Batch insert from XML File?
- How to Download and install plugin database remotely
- How to insert data to a database table when the field is not yet created?
- Where to store the name of a custom table?
- include wp-blog-header not working on MAMP
- creating custom function to log actions in plugin
- SQL query for custom taxonomy slugs
- Issue regarding $wpdb->prepare()
- Error on inserting a form value to database
- How to create database table, add data, update and delete using wpdb via plugins?
- Using WPDB to output raw XML fails because of wp-blog-header.php
- how to search users by ajax live search
- Adding custom end points, No error line
- Intermittent database errors when accessing WordPress database
- Storing data in wordpress database from ajax call from different website
- wpdb->prepare and mysql UPDATE – how is it done?
- $wpdb->prepare with LIKE and sprintf
- How to optimize multiple insert into wordpress database
- $wpdb->update() always need a second try
- Data inserted by wpdb insert is different than data pressnt in database.
- Proper Prepare Statement for ALTER TABLE and using AFTER
- $wpdb->prepare is not working like mysql_real_escape_string
- How to avoid conflicts with db.php / $wpdb and other plugins that decide to use them?
- $wpdb in php 5.5
- Plugin to create Posts and Forums then choose category and parent forum
- $wpdb->update Issue
- How to relate the Category to user?
- WordPress database error: [Query was empty] – using $wpdb->prepare()
- Why doesn’t my Table get created?
- How to display specific data from a custom table to logged in users with a custom role
- $wpbd->insert_id is returning null
- How to store sensitive user data (passwords)
- How to get inserted row IDs for bulk/batch insert with wpdb query?
- WordPress Query doesn’t return the correct value
- User avatar-ACF fields
- bindParam? WordPress 4.9.5 SQL LIKE statement %s and %LIKE%
- Update database record in plugin
- Dedicated server and WPDB Class : huge slow-down of the website
- How to implement pagination into a wpdb->result query?
- How to CRUD from wordpress database in wordpress theme?
- I can’t write in my DB using $wpdb->insert
- $wpdb how can i save my postmeta table before querying it
- WordPress plugin tables become corrupt
- Nothing happens on WordPress Update command
- multiple record insert creating many duplicate records
- Is There a Plugin Life Cycle Documentation?
- What is an alternative method to the WordPress private _doing_it_wrong() function
- Shortcode adding p and br tags
- Having Problem On Getting WP Post Gallery Images URL
- Can I dynamically create a link to my plugin settings/options page from my plugin description?
- How to load the plugin only when logged in?
- Hook into theme-switching later than `setup_theme`
- Save image as featured image
- WP AJAX is not working, always returns 0
- Admin auto-refresh is interfering with Firebug — how to prevent it?
- Hide plugin dashboard menu item for specific roles
- WordPress mode for emacs?
- Widget translation on my plugin
- Upload to a remote server using wp_remote_post
- conditionally load javascript & CSS for do_action() calls from plugin
- The plugin does not save data
- How do I create plugin or theme using MVC pattern?
- Create custom HTML/JS app inside page
- tinymce.get() returns error after ajax request
- Access bloginfo, get_option, and plugins_url from a non-core php file
- Upload multiple images and insert them into custom html code
- How to get a list of child ids for a named category?
- Plugin could not be activated because it triggered a fatal error, unexpected ‘[‘
- How to make the first commit on WordPress.org
- How best to handle database version dependence (from $wp_db_version)
- Associate multiple email addresses with the same user account, so they can log in with either
- How to grab query string from wp-content/uploads/.*
- What is the way to hook all wordpress email
- Configure WordPress to Generate Scheme-less Relative URLs
- Best way to distribute templates and code accross multiple wordpress sites?
- Modify code for functions.php with specific twitter user url and hashtags
- get_the_date() returns english Year & Day when language is Arabic
- Where to save Gutenberg plugin data?
- Add new header/footer on landing page with plugin
- Multi hook deploiement
- Endpoint Callback Display for Custom Plugin
- Get Commentor IP When Marking Comment As Spam
- Best practice to include custom user styles in widgets
- Sending Parameter Failed
- How to design WooCommerce-like admin tabs for plugin settings page?
- Woocommerce: block user removing cart item