wpdb

Wordpress: How to unescape the results when using $wpdb->get_results?

痞子三分冷 提交于 2019-12-08 16:00:47
问题 To add a new rows to the database I use $wpdb->insert , and to get the rows I use $wpdb->get_results . The problem is that $wpdb->insert seems to be escaping the input. For example, a"b is saved as a\"b in the database. But, $wpdb->get_results doesn't seem to unescape back a\"b to a"b . Is this the correct behavior by design? Should I unescape the result of $wpdb->get_results manually? (What is the proper function for this?) 回答1: $wpdb->insert() and $wpdb->prepare() will escape data to

Wordpress Plugin Calling Database Results via AJAX

陌路散爱 提交于 2019-12-08 03:53:01
问题 I have written a Wordpress plugin which generates content for a page, then tries to call Update.php via jQuery.load to refresh the results. For example: Plugin generates this content: global $wpdb; $sql = "SELECT * FROM table ORDER BY id;"; $results = $wpdb->get_results($sql); <div id="content">Database Results Here Via Loop</div> jQuery calls Update.php: <script type="text/javascript"> $(function() { var refresh = setInterval(function() { $("#content").load("Update.php"); }, 5000); });

$wpdb->insert not working. No Error Msg

笑着哭i 提交于 2019-12-05 21:00:50
问题 Got the lower portion here sorted, but now there's an issue when it inserts the record. I have the NULL value for file formatted as %s for string, but it's not inserting NULL it's inserting [BLOB - 0B] . The column format in the mySQL table is longblob . Any ideas? this is my first time using $wpdb->insert and it looks like I've missed something. Here's the loop I'm trying to use. There are currently 2 timestamps in the array. for ( $i = 0; $i < count($timestamps); $i++ ) { $working_time =

Converting mysql_query to $wpdb->get_results

柔情痞子 提交于 2019-12-02 08:36:22
Afetr updating php on the server i have some problems with mysql_query. There are 2 functions in your code that have been deprecated in the current version of PHP : mysql_fetch_array() mysql_query() global $table_prefix, $wpdb; // caching database query per comment $ck_cache = array('ck_ips'=>"", 'ck_comment_id'=>0, 'ck_rating_up'=>0, 'ck_rating_down'=>0); $table_name = $table_prefix . "comment_rating"; if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) { temckrating_install(); } function temckrating_install() //Install the needed SQl entries. { global $table_prefix, $wpdb;

How to convert this prepare statement to use placeholders in Wordpress $wpdb?

喜夏-厌秋 提交于 2019-12-02 08:26:43
I have a perfectly working wpdb prepare statement before Wordpress 3.5. This is my line: $post_id = $wpdb->get_var($wpdb->prepare( "SELECT a.post_id FROM $metatable AS a JOIN $metatable AS b ON a.post_id = b.post_id WHERE a.meta_value = '$valuex1' AND b.meta_value = '$valuex2'")); Now with Wordpress 3.5, this returns a warning since this is not fully sanitized. I have modified this to use placeholders as advised by Wordpress: $post_id = $wpdb->get_var($wpdb->prepare("SELECT a.post_id FROM $metatable AS a JOIN $metatable AS b ON a.post_id = b.post_id WHERE a.meta_value =%d AND b.meta_value =%s"

Paginate Wordpress $wpdb Query?

北战南征 提交于 2019-12-01 13:23:32
I have this query: <?php $query= "SELECT wposts.* FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = 'votes' AND wposts.post_status = 'publish' AND wposts.post_type = 'post' ORDER BY CAST(wpostmeta.meta_value AS SIGNED) DESC LIMIT 10"; $posts = $wpdb->get_results($query, OBJECT); if ($posts ) : foreach ($posts as $post): setup_postdata($post); ?> // Post here <?php endforeach; endif; ?> <div class="pagination"> <?php wp_pagenavi(); ?> </div> I'm using this because Wordpress can't properly order meta_values that uses numbers, anyway.

Paginate Wordpress $wpdb Query?

旧街凉风 提交于 2019-12-01 10:39:15
问题 I have this query: <?php $query= "SELECT wposts.* FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta WHERE wposts.ID = wpostmeta.post_id AND wpostmeta.meta_key = 'votes' AND wposts.post_status = 'publish' AND wposts.post_type = 'post' ORDER BY CAST(wpostmeta.meta_value AS SIGNED) DESC LIMIT 10"; $posts = $wpdb->get_results($query, OBJECT); if ($posts ) : foreach ($posts as $post): setup_postdata($post); ?> // Post here <?php endforeach; endif; ?> <div class="pagination"> <?php wp_pagenavi();

How to insert data using wpdb

青春壹個敷衍的年華 提交于 2019-11-28 16:33:31
I have wriiten as following $name="Kumkum"; $email="kumkum@gmail.com"; $phone="3456734567"; $country="India"; $course="Database"; $message="hello i want to read db"; $now = new DateTime(); $datesent=$now->format('Y-m-d H:i:s'); global $wpdb; $sql = $wpdb->prepare( "INSERT INTO `wp_submitted_form` (`name`,`email`,`phone`,`country`,`course`,`message`,`datesent`) values (" $name, $email, $phone, $country, $course, $message, $datesent. ')")'; $wpdb->query($sql); It's not working... It throws error... Please help me in correcting it. Nadh Use $wpdb->insert() . $wpdb->insert('wp_submitted_form',

Hook AJAX in Wordpress

倾然丶 夕夏残阳落幕 提交于 2019-11-27 15:56:00
I have been delving into the world of Javascript and AJAX. I am super close, but for some reason I do not think I am hooking into wordpress ajax functions right. I have poured through the docs and this and think it is 99% there. Is what this app does is there is a list of items. Each one with a + button. Clicking the button pops up a confirm box, and if confirmed grabs the needed data to pass to the php. The php adds the item into mysql with wpdb->insert. It also does some changes if you buy. The js works all the way up to the call, grabbing the right values etc. Testing the php separately

Issue when trying to use IN() in wpdb

倾然丶 夕夏残阳落幕 提交于 2019-11-27 14:47:03
i have this: $villes = '"paris","fes","rabat"'; $sql = 'SELECT distinct telecopie FROM `comptage_fax` WHERE `ville` IN(%s)'; $query = $wpdb->prepare($sql, $villes); when I do an echo $query; i get: SELECT distinct telecopie FROM `comptage_fax` WHERE `ville` IN('\"CHAPELLE VIVIERS \",\"LE MANS \",\"QUEND\"') the probleme i have is that $wpdb add ' in IN('...') can someone help, thanks Try this code (FIXED): // Create an array of the values to use in the list $villes = array("paris", "fes", "rabat"); // Generate the SQL statement. // The number of %s items is based on the length of the $villes