FAQ Database Discussion Community


Ajax Form Success Data is always empty

jquery,ajax,wordpress,wpdb
I am trying to run a wordpress wpdb->get_results select query and I want to get the search criteria from a textbox. I want to do it form and with ajax without refreshing the page. No matter what I do the textbox value that I enter into search textbox is always...

Submitting one out of many inputs on a page to mysql database using wordpress

php,mysql,wordpress,wpdb
At current I managed to get a form on a wordpress page to submit data to a mysql database (a very large victory for me; not big into php/coding) This is the code I have been using, but need help changing: <form method="post"> Value1: <input type="text" name="field1" /> Value2: <input...

$wpdb returns duplicate posts

php,wordpress,wpdb
I have created a shortcode which shows the posts which were created after the user last logged in. The shortcode is working perfectly fine, but I am not sure why but I am getting 7 duplicate posts. So like for test I created a post named as "Sample Article", and...

How to write following queries in $wpdb

php,mysql,wordpress,wordpress-plugin-dev,wpdb
Migrate from mysql to $wpdb so I need to do following queries in $wpdb how to do it? $result = mysql_query( 'SHOW TABLES LIKE "wp_%"' ); $table_descr_query = mysql_query("SHOW CREATE TABLE sites"); I tried like $wpdb->get_results( 'SHOW TABLES LIKE "wp_%"' ); but it doest not works and $wpdb->get_var("SHOW TABLES LIKE...

Counting daily and hourly results in mySQL

php,mysql,database,datetime,wpdb
I have two tables in mySQL, one for views and one for downloads with the following key structure: ip | hit --------------------------------------- 127.0.0.1 | 2015-02-08 15:16:59 127.0.0.1 | 2015-02-08 15:20:22 127.0.0.1 | 2015-02-08 15:20:35 127.0.0.1 | 2015-02-08 15:21:13 10.0.1.1 | 2015-02-09 16:29:13 10.0.1.1 | 2015-02-09 16:42:12 10.0.1.1 | 2015-02-09 16:52:30...

Wordpress - wpdb query does not list same result as sql query

php,mysql,wordpress,wpdb
I have a very weird issue with wpdb which is freaking me out. My database has the following data: INSERT INTO `wp_clb_likes` (`id`, `post_id`, `user_ip`, `time`) VALUES (5,11511,'::1','2015-01-25 09:23:26'), (6,11511,'::1','2015-01-25 09:23:34'), (7,11511,'::1','2015-01-25 09:24:07'), (8,11511,'::1','2015-01-25 09:24:44'), (9,11511,'::1','2015-01-25 09:28:53'), (10,11511,'::1','2015-01-25 09:29:23'), (11,11511,'::1','2015-01-25 09:31:06'), (12,11511,'::1','2015-01-25 09:31:30'), (13,11172,'::1','2015-01-25 09:43:10'),...

Get Meta Value for all Posts via $wpdb

php,mysql,arrays,wordpress,wpdb
I wrote a function which should give you the value of a meta key for all of the posts. I am not sure why my query is not working. It gives me an empty array as output when I var_dump the query. The value of the meta key is stored...

Displaying mysql query in specific tags for wordpress

php,mysql,wordpress,wpdb
This is the query I'm currently using. It's purpose is to take a percentage of all the values in a column, and output the highest percentage value. <?php $wpdb->query( " SELECT COUNT(field1) as totals FROM test GROUP BY field1 ORDER BY totals DESC", ); ?> Here is the structure of...

Results are empty with $wpdb->prepare statement

php,mysql,wordpress,sql-injection,wpdb
I am working in WordPress and my $wpdb select query works without prepare but when I use the proper escaping and use $wpdb->prepare ... with prepare results never show up and results show when I don't use %s and prepare ... what is there that I am missing ... thanks...

Query based on custom field

wordpress,wordpress-theming,advanced-custom-fields,wpdb
I have made custom fields using advanced custom field plugin. It has a field name school which includes choices such as arts,education,engineering. Now my problem is how can i query only those post who field is arts using wpdb. sincerely i don't know wpdb works. . Any help will be...

wpdb - add up values for custom field within a specific category

php,wordpress,wpdb
I have a custom field called "points." This is a numerical value, so some posts have 2 points, some have 10, etc. I want to count the total number of "points" for all of the posts within a given category who also have the custom field "cf_Category" with the value...

Which one is best mysql or mysqli or $wpdb for wordpress plugin

php,mysql,wordpress,mysqli,wpdb
I have created a plugin in wordpress after updated latest version of php my mysql_connect does not work. shows error like PHP Fatal error occurred: Call to undefined function mysql_close() I know it is a PHP version problem so I need to migrate to mysqli but I have a doubt...

Fetch Posts Based on Multiple Ratings foreach Taxonomy

php,mysql,sql,wordpress,wpdb
I am setting ratings of posts based on the taxonomies, lets say, now i want to query them based on ratings and taxonomies. an app on PC has rating 10. (meta_key=rating_pc) an app on Android has rating 5. (meta_key=rating_android) add_action( 'posts_where', 'minscoreaction' ); function minscoreaction( $sql ){ global $wpdb; $minscore...

$wpdb->prepare is not working like mysql_real_escape_string

php,mysql,wordpress,wordpress-plugin-dev,wpdb
I'm working on a WordPress plugin and recently I have planned to migrate from SQL to $wpdb. I'm using a method called $wpdb->prepare instead of mysql_real_escape_string but it does not work. Here is what I tried: Code: echo $fetch_row; Output: a:5:{s:9:"task_name";s:10:"Backup Now";s:9:"mechanism";s:10:"singleCall" Code: echo mysql_real_escape_string( $fetch_row ) Output: 'a:5:{s:9:\"task_name\";s:10:\"Backup Now\";s:9:\"mechanism\"...

wpdb & wp_query order by return wrong values

mysql,database,wordpress,wpdb,wp-query
i wanna get results from wp_postmeta order by DESC their values.i use this codes : $top_query = $wpdb->get_results("SELECT meta_value FROM wp_postmeta WHERE meta_key = 'sd_top_numbers' ORDER BY meta_value DESC"); foreach ($top_query as $details) { echo $details->meta_value; echo '<br/>'; } output! 8800 8900 9600 9700 15700 16200 i also try wp_query...