Using “->” in a page to exceute $wpdb query gives error

Code is Code and content is content and they should not be mixed together. the editor is not a code editor, the content can and usually will be transformed in a way you don’t expect which might result in your code failing with no obvious reason. Just don’t do it. Write your own shortcode that … Read more

How to insert dash (-) into database using wpdb and new_to_publish hook?

When we call get_the_title(), then the post title is taken through the wptexturize() function via the the_title filter: add_filter( ‘the_title’, ‘wptexturize’ ); The en-dash and em-dash are replaced with /* translators: en dash */ $en_dash = _x( ‘–’, ‘en dash’ ); /* translators: em dash */ $em_dash = _x( ‘—’, ’em dash’ ); A simple … Read more

Proper Prepare Statement for ALTER TABLE and using AFTER

Answer to this question actually comes from @TomJNowell. Instead of using MySQL calls, use the native functions included with WordPress: update_post_meta ( $post->ID , ‘forum_id’, $thread_id ); where the forum_id is the key and the $thread_id is the value. I tried add_post_meta but that created duplicates. To retrieve the meta data $thread_id = get_post_custom_values( ‘thread_id’, … Read more

WPDB – Read and write value from / to database

This is still a valid question even if there is an easier way. That easier way is get_user_meta($user_id,’vatnumber’,true); NOT $wpdb->get_user_meta($user_id, vatnumber,”); by the way. Setting the $single flag to true is because although you can store multiple values in a single keyname but this is usually best avoided to avoid confusion. Since you are getting … Read more

Data inserted by wpdb insert is different than data pressnt in database.

wpdb::insert will only ensure that data is inserted safely (i.e prevents against SQL injection). It will not sanitize your data (e.g. stripping certain/all HTML), that’s down to you. You can either use wp_strip_all_tags, which removes all HTML, or a variation of wp_kses, which is a sophisticated library for removing certain (x)HTML tags & entitites. The … Read more

Filter authors on meta value

Is there a specific reason you aren’t using WP_User_Query? It would make it easier to do what you want to. You can read up on it here. Something along these lines would solve your problem, as far as I understand it: $args = array( “meta_key” => “ArtistCategory”, “meta_value” => “X” //or “Z” ); $authors = … Read more

Change MySQL PDO connection to a WPDB connection

You need to repalce the PDO connection object with WPDB object. And for the kind of query in your example, looks like the best way to do it is with $wpdb->getcol. Something like this (didn’t test): if ( isset( $_GET[‘term’] ) ){ global $wpdb; $term = filter_var( $_GET[‘term’], FILTER_SANITIZE_STRING, FILTER_NULL_ON_FAILURE ); if ( is_null( $term … Read more

WordPress wpdb->insert returns int(0) => doesn’t insert anything, no errors!

Your format is wrong. On your code is should be $insertion = $wpdb->insert($wpdb->prefix . ‘table-name-of-plugin’, array( ‘column-name’ => $stringValueForC1, ‘second-column-name’ => $stringValueForC2 ), array(‘%s’, ‘%s’) ); Notice the change from array(‘%s, %s’) to array(‘%s’, ‘%s’) Also, since you are setting the format for both of the value as string. I recommend that you just use … Read more

Mowing site to another domain in simplest way

Unfortunately there’s nothing native in WordPress to handle searching and replacing your domain name across all your posts, options, etc. The closest you can get is WP-CLI’s search-replace command. It’s not an official WordPress project, but it has quite a high adoption rate, it’s very well maintained and available by default or on demand on … Read more

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