The wpdb class, accessed via the $wpdb global variable, is used to interact with the WordPress database

learn more… | top users | synonyms

0
votes
0answers
10 views

WordPress database error Duplicate entry 'cron' for key 'option_name' for query

Today i see the error's with my website and it seems to slow down the performace of the website when i was having very high traffic on the website. I bought Vaultpress plugin for the backup and i was ...
1
vote
1answer
19 views

Alter a specific query on Wordpress

I need to change a query of a plugin that is not the main query. The author did not put any filters. I can see the query from $wpdb->queries Is there a way to access the specific query and ...
-2
votes
0answers
43 views

Already has more than 'max_user_connections' active connections wp-db.php

ERROR : mysql_connect() [function.mysql-connect]: User already has more than 'max_user_connections' active connections in /nfs/c09/h01/mnt/12345/domains/domain_name/html/wp-includes/wp-db.php on ...
0
votes
0answers
20 views

Fetching array of postmeta with $wpdb and in_array conditional

I'm trying to fetch an array of all entries to a specific meta key and then check to see if the user input value exists in that array. I've checked the data base for the query and I see the meta ...
0
votes
1answer
270 views

wpdb inside foreach loop only returns first result - 2 other similar cases found

@Milo Problem solved, found spaces in the array $arrname. I was trying to get post id using post_name. First of all I stored all post_name in an array an then loop through the array to use the key ...
0
votes
0answers
6 views

Custom table in my plugin print UTF-8 (מוברש) charsets and not hebrew

i have created custom table in wordpress db to use my plugins needs. i have campaigns with hebrew names, this saved to column (varchar(100) utf8_unicode_ci ) in the DB i dont see hebrew but this: ...
0
votes
0answers
19 views

How to use ajax in wordpress plugin to get data from coustom DB?

i have created php script that work great as stand alone. now i need to create this script as wordpress plugin. so i have created custom table in wordpress DB. then i tried to make the ajax call. in ...
1
vote
2answers
24 views

wpdb custom post_type problem

I want to use custom post type in my custom SQL query, but, when I add the custom post type im my query, I get no results. Where's my probelm ? This is the code I've tried $top5_ov_performance = ...
0
votes
2answers
314 views

Call to a member function get_results() on a non-object in wordpress plugin

I am using revolution slider plugin. I got above error while executing one of my front end form. This is my code in that file.. <?php class UniteDBRev{ private $wpdb; private $lastRowID; ...
0
votes
1answer
18 views

Order by in foreach

hello im getting post_id by using wpdb after that i wanna show postmeta(sd_l2) order by their value i uses this codes global $wpdb $top5_ov_performance = $wpdb->get_results("SELECT post_id FROM ...
3
votes
1answer
505 views

Is it true $wpdb->get_results is faster than WP_Query in most cases?

On my homepage, I have a section where I have to display the last five featured posts, where a featured post is simply a post with a custom field is_featured set to 1. I achieved what I want with two ...
4
votes
3answers
722 views

How might I retrieve a featured post image from an external WP site and display it as a link back?

I have two WP sites. I want to reach from one of them, into the other, and retrieve specific featured images for posts, and display them with a link to that post. I am using this line (with the ...
3
votes
1answer
298 views

Change post status based on meta value

I have this cron set up to trash posts x days after it is posted. This works. Edit: Added my answer to my question. add_action( 'wp', 'do_trash_ads' ); function do_trash_ads() { if ( ! ...
0
votes
0answers
10 views

Unable to create custom table , register_activation_hook from class

Cannot create the table , what am i missing class em_db { public function em_events_custom_table() { global $wpdb; $table_name = $wpdb->prefix . "em_events_db"; ...
0
votes
0answers
14 views

run search / query from multiple databases

First of I would like to warn everyone, that my skills set in mysql and php is novice. My current wordpress website is based on a network setup (mutli-site), with the help of shardb, I was able to ...
0
votes
0answers
37 views

Storing PHP structure data in the wp_options table?

I searched too much about that but can't find resonable answer of that question I am creating a WordPress plugin that has so many options that I need to store so to store data using option API which ...
0
votes
0answers
23 views

Wordpress WP_Query post__in

I try to get value from database==> postmeta ==> Meta value : value Using this code $promo_value = $wpdb->get_results("SELECT meta_value FROM $wpdb->postmeta WHERE meta_key = '_product_id' ...
0
votes
2answers
24 views

Custom Wordpress Table wpdb

running into issues querying a custom table and getting results. As of Wordpress 3.9, I can no longer run mysql_query(), and have to use $wpdb->query(); So keeping that in mind: Old Code: <?php ...
0
votes
3answers
29 views

selecting row using wpdb which contain special symbols

I got a table with one of the column have special charaters. I inserted to the table as $sql=$wpdb->prepare( "INSERT INTO `mytable` ( `question`, `remarks`) VALUES ...
1
vote
1answer
329 views

wpdb->insert and stripslashes against sql injection

I've been reading the codex at this page: http://codex.wordpress.org/Function_Reference/stripslashes_deep The code i wrote before reading that page is this: $data = array( 'col1' => ...
0
votes
1answer
1k views

$wpdb error (Call to a member function insert() on a non-object)

I have very few knowledge on oo php and databases, and I am simply trying to insert data in my wp_pagesvisites table but I am having some trouble with this error message. This is my script: ...
0
votes
4answers
189 views

Displaying post excerpt using wpdb query

I'm using a modified version of the code from a question (Get WordPress Posts Grouped by Month) to group my posts by year. Everything is working fine, but I'm having trouble getting the post excerpt ...
0
votes
1answer
296 views

How to fetch records from database WordPress

index.php: <?php $new=$wpdb->query("select * from wp_posts where post_title='Auto Draft'"); $new1=mysql_fetch_row($new); echo $new1[0]; ?> How to fetch record from database? How ...
1
vote
1answer
337 views

Wordpress choose wrong database

I have 2 databases. When I include the database connection (with a include('filename.php');) wordpress acts really strange. I can't login, the wordpress username and password is right but it tries to ...
0
votes
0answers
36 views

Insert data to DB

I create plugin and that plugin, when is activate, create new table in DB.. Now i need to insert some data like (firstname, lastname..) in that table.. Here is my form : <form name="cool_form" ...
0
votes
0answers
27 views

$wpdb error : call to a member function insert() on a non-object

I'd like to add data to my custom wordpress table of my plugin, here is my code: <?php global $wpdb; $data = $_POST['name']; $wpdb->insert('ct_data' , array( 'name' => $data ), array( "%s" ...
1
vote
3answers
341 views

Detect featured image among the attached images

I use the following code to extract the attached images from a post with ID: $args = array( 'post_type' => 'attachment', 'post_parent' => $product_id, ...
0
votes
1answer
356 views

Action hook “wp_insert_post” works but not for last imported post

I want to run a custom function whenever posts are imported to my custom post type. I am currently running this code - function on_post_import($post){ global $wpdb; $results = ...
0
votes
0answers
27 views

Get results from wordpress data custom table

Firstly i created a custom table into the wpdb : global $wpdb; $table_name = $wpdb->prefix . 'countdown_table'; $sql = ' `id` int(11) NOT NULL AUTO_INCREMENT, `styleName` varchar(255) ...
0
votes
0answers
28 views

Custom post type search shows “Not unique table/alias” error

If I search for a value on the page that shows the custom post type list ( edit.php?post_type=my_post_type ) then it returns normal results. But because I wanted to include the post meta fields in ...
0
votes
0answers
18 views

wordpress plugin admin area save settings

I am brand new in wp plugin development and i need your help cause throw web the answers that i find confused me. So i would like to make a countdown timer wp plugin for my website that will display ...
0
votes
1answer
33 views

How to fetch results from database

I'm attempting to customize a wordpress theme. I've added custom field cp_job with form submission. This indicates if the ad is either Buyer(Buying services) or Seller(selling services), which is now ...
0
votes
0answers
19 views

$wpdb->get_results in not an array

Using get_result I receive an "Invalid argument supplied for foreach()" because is not an array. I tried with get_col but I don't know how to extract the data and I don't know the difference between ...
0
votes
1answer
52 views

Retrieving posts by their date and category

I'm trying to create a plugin for displaying post titles and dates (which will be displayed as links to those posts) of a specific date range and category. So far I have managed to get to display the ...
2
votes
2answers
71 views

Why does dbDelta() not catch MysqlErrors?

From what I can see, dbDelta() is designed to suppress database errors that occur during its operation. Generally speaking, this seems to be the case, but New Relic is still reporting MysqlErrors ...
0
votes
1answer
14 views

$wpdb variable throw this error Call to a member function get_results() on a non-object in

I've this error "Call to a member function get_results() on a non-object in" from this code: require_once($_SERVER['DOCUMENT_ROOT'] . $folder . '/wp-config.php'); ...
0
votes
0answers
48 views

Why are Wordpress e-mails full of “mysql_real_escape_string” errors? (wp-db.php)

Since recently all Wordpress e-mails, which include Woocommerce order confirmation emails, are full of errors like these: Warning: mysql_real_escape_string(): 19 is not a valid MySQL-Link resource in ...
2
votes
1answer
2k views

How to use wildcards in $wpdb queries using $wpdb->get_results & $wpdb->prepare?

I am attempting to make a custom search for BuddyPress groups. Here is my method: public function search_groups($string){ global $wpdb; $results = $wpdb->get_results($wpdb->prepare( ...
0
votes
1answer
46 views

List of ways to access WordPress database?

I'm trying to get a complete understanding of how WordPress works with databases. I've read the documentation but I'm getting confused by all the different approaches available. So far my ...
3
votes
1answer
80 views

WP_Query to work with custom view

I have created a Database VIEW on wp_posts which selects its all columns and exposes an extra calculated columns (average). So my View is identical to wp_posts plus one column, which I want to use for ...
1
vote
1answer
43 views

$wpdb - do you have to use foreach even if there will always only be one result?

I have a $wpdb query that will always only return one result. This is a simplified version of it: $results = $wpdb->get_results ( "SELECT name FROM testTable WHERE id=1" ); Do I have to use ...
0
votes
1answer
29 views

Should I use an additional column in the DB?

I'm building a site for a client. They need a functionality where WordPress can tell if a logged in user has viewed a post in order that they might serve a notice or hide the original content. I ...
0
votes
1answer
23 views

Unknown column 'siteurl' in 'where clause' WPDB outside

I am trying to get Mysql values from outside wp. My code: define( 'BLOCK_LOAD', true ); require_once( $_SERVER['DOCUMENT_ROOT'] . '/wp-config.php' ); require_once( $_SERVER['DOCUMENT_ROOT'] . ...
3
votes
2answers
100 views

Differences between wpdb->get_results() and wpdb->query()

Who can explain me the differences between wpdb->get_results() and wpdb->query() in making generic queries to wordpress db?
1
vote
2answers
1k views

Increment value (value = value+1) of $wpdb->update

This sql query $wpdb->query("UPDATE log SET total=total+1 WHERE id='1')"); How do I turn it into $wpdb->update() statement? Ex. $wpdb->update('log', array('total'=>'total+1'), ...
1
vote
1answer
959 views

wpdb->insert multiple record at once

So after I have created the table 'settings-table' i want to add a couple of records to it. This is how I want to do it, not the best way, so I need a better way to do this because I will add more ...
0
votes
1answer
45 views

Inserting a MySQL record into a table with an array of field names and an array of values

I see this in the Codex: $wpdb->insert( $table, $data, $format ); I'm using this type of code and it works: $wpdb->query( $wpdb->prepare( "INSERT INTO `table` ...
0
votes
2answers
62 views

Perform a function when a user clicks register button

I am kind of new to WordPress coding. I'm trying to edit the wp-login.php file so if a user clicks the register button, it registers the user and stores the information in a different database table. ...
0
votes
1answer
31 views

Incorrect Use of wpdb::prepare()

Not sure what I am doing wrong here. I did not write this code however I am receiving the following error in WordPress: The query argument of wpdb::prepare() must have a placeholder. This message ...
0
votes
0answers
92 views

Inserting data into custom tables

I am trying to create custom input tables to send data into custom tables on the wp database. I cannot get my script to do anything. The user will enter a type of liquor, like vodka or whiskey, ...