Can’t call WPDB inside RSS template

After discussing we’ve discovered the problem isn’t directly with calling $wpdb->get_row but a mismatch between the data it returns and the processing in the foreach loop. For a single row of data, replacing… foreach($beforeAfter as $imageSet) { ?> <item> <title><?php echo get_the_title($imageSet->ID); ?></title> </item> <?php } … with … <item> <title><?php echo get_the_title($imageSet->ID); ?></title> </item> … Read more

prepare function sql safe method

Both methods are okay ($new_wpdb->insert actually uses $new_wpdb->prepare) and provide the same level of safety when it comes to SQL escaping. $new_wpdb->insert is the preferred method unless you’re writing your own custom SQL query.

Understanding custom php that reads from WP MYSQL

Have you looked at the server log files (MySQL and PHP)? It could be several things: A MySQL permission issue on the db and/or table Table is named differently than stated in your code MySQL and/or WordPress are using older versions that don’t support certain syntax

Update multiple rows in one query

I googled a lot the last days and a few times i´ve seen postings that say that the $wpdb->update function doens´t support multiple updates and that this is not well documented. -> Sorry i don´t have links anymore… I think that this is true because i couldn´t get it to work and i found not … Read more

Getting values from wpdb

You are not too far away from your goal. The get_calendar_ids must return only $calendars. In your function $wpdb->get_results( $sql ) will return an object with the datas your asked. function get_calendar_ids() { global $wpdb; $user_id = get_current_user_id(); $sql = $wpdb->prepare( ” Select wp_calendars.user_id, wp_calendars.name, wp_calendars.id From wp_calendars Where wp_calendars.user_id = ‘$user_id’ “); $calendars = … Read more

How to use AJAX in WordPress in MYSQL query?

In WordPress it little bit complicated then default way to handle ajax form data. odify your js code like this. function ajaxSubmit(e){ // prevent the default action. e.preventDefault(); var myform= jQuery(this).serialize(); jQuery.ajax({ type:”POST”, // Get the admin ajax url which we have passed through wp_localize_script(). url: ajax_object.ajax_url, action: “submitAjaxForm”, data: myform, success:function(data){ jQuery(“.records”).html(data); } }); … Read more

wpdb query not working

It’s probably because you must use % sign for “like” so it would be: SELECT * FROM `wp_usermeta` WHERE meta_key= ‘referrer’ AND meta_value LIKE ‘%270%’ AND meta_key= ‘view_type’ AND meta_value LIKE ‘%invoice%’

$wpdb->prepare affecting the query?

You can use the array directly because the $wpdb->prepare() method can be called like vsprintf(), which works like sprintf() but accepts arrays of arguments. $post_types = get_post_types(); unset( $post_types[‘attachment’], $post_types[‘nav_menu_item’] ); global $wpdb; $replace_query = $wpdb->get_results( $wpdb->prepare( “SELECT * FROM $wpdb->posts WHERE post_type IN ( %s )”, $post_types ), ARRAY_A ); The problem with your … Read more

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