Which is better and faster ? WordPress Queries or SQL Query

Queries ofcourse. It’s faster… But in this case just please delete you wp site and start with something faster… here is my superfast framework for you… <?php /*Your bunny wrote */ I did tests, 0.0000001 runtime vs WP usually 0.7-2.8 Sarcasm off P/S/ This question have no sence since using direct queries and output of … Read more

Insert Query not working in the form

I figured out my error in the query, Thank you all guys for responding, I just gave the piece of code <?php global $wpdb; $contactus_table = $wpdb->prefix.”contactus”; //error with the query $sql = “INSERT INTO $contactus_table (firstname, lastname, email, query, reg_date) VALUES (‘$firstName’, ‘$lastName’, ‘$email’, ‘$query’, CURRENT_TIMESTAMP)”; if($wpdb->query($sql)) { $BlogName = get_bloginfo(); echo $BlogName; } … Read more

Inner Join user tables to select users with roles

The Problems You risk SQL injection, with your current setup: $wpdb->users.display_name LIKE ‘$ltr%’ The following could also be a problematic part in your SQL query: AND $wpdb->usermeta.meta_value = %artist% i.e. using = instead of LIKE. You’re also missing the quotes: %\”artist\”%, to exclude e.g. bartist or fartist 😉 But you don’t need to construct this … Read more

WPDB Placeholders and second argument for prepared statements

Just use %s for string and %d for digit replacements. Do not forget to use the proper esc_*() functions (use full text search for esc_ in the function reference). global $wpdb; $wpdb->show_errors = true; $wpdb->suppress_errors = false; ! defined( ‘DIEONDBERROR’ ) and define( ‘DIEONDBERROR’, true ); $sql = <<<SQL SELECT ID FROM {$wpdb->posts} WHERE post_type=”attachment” … Read more

How to pass orderby params to $wpdb->prepare()?

You don’t need to use $wpdb->prepare() for ORDER BY clauses. $wpdb->prepare() will always quote your variables. Supposing you receive the ordering in the request, you can prevent SQL injection by not using the user entered value at all: $sql = “SELECT….”; if ( ‘asc’ == $_GET[‘order’] ) { $sql .= ‘ ORDER BY p.post_date ASC’; … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)