WPDB SQL query with prepare() returning variable, not db value
The function bbp_forum_id() will directly echo its value, you want to use bbp_get_forum_id() which will return the value for use in the context of an API call.
The function bbp_forum_id() will directly echo its value, you want to use bbp_get_forum_id() which will return the value for use in the context of an API call.
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
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
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
Try this SQL query: UPDATE wp_terms SET name=LOWER(name);
Look at this Bulk post type conversion, there are listed SQL/WP ways to do that. Try to do that yourself first with a db copy. In phpMyAdmin there is a box to run queries, called “SQL”. You can see a demo here http://demo.phpmyadmin.net/master-config/
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
Deleting a plugin deletes all its code, but doesn’t necessarily delete data it’s added to the database, or additional tables it may have created. Whether a plugin can or does delete its own data depends entirely on the plugin. In my experience, the vast majority do not, and those that do usually have a setting … Read more
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
To get the number of posts you can do it easily without a second query with $adsQuery->post_count; But if there’s some reason (I’d love to know the context!) I can’t grasp that the same query has to be run twice and to the database directly- to answer your question as to why it’s not working: … Read more