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

learn more… | top users | synonyms

0
votes
1answer
230 views

after wordpress update to 3.5+ i get many errors in plugin wpdb::prepare()

after wordpress update to 3.5+ i get many errors in this plugin. i found that the reason is: http://make.wordpress.org/core/2012/12/12/php-warning-missing-argument-2-for-wpdb-prepare/ I do not ...
0
votes
1answer
93 views

$wpdb - joining shows no result

For one of my client's WP site, I'm making a plugin, where I'm using the db Query. I've two custom tables dedicated to the plugin: user_req — stores user chosen posts along with some custom ...
0
votes
0answers
24 views

Calculation for each custom post type

I have a code looking like something like this: (It calculates number of registered members for each course) foreach($courses as $course) { global $wpdb; $sql = "SELECT COUNT(*) FROM ...
0
votes
2answers
95 views

Accessing two databases wordpress

I'm trying to access a second database with my wordpress system. To do this, I've attempted to follow the advice found here which seems to have worked for a lot of people. In summary, I'm adding ...
0
votes
1answer
146 views

Delete/replace img tags in post content for auto published posts [closed]

In my blog I have set up auto-publish for posts and I get 5 thousands new posts every day, in this moment I have more than 150 thousand posts. I need a script, or a plugin, or a function to connect ...
1
vote
1answer
254 views

Creating a post from data returned from HTML form

I am trying to write a WordPress plugin and I have hit a bump. The Background: I have some data in a mySQL DB that I am using (each row has a unique ID and some other information I have added). I am ...
1
vote
0answers
379 views

$wpdb->insert() does not Insert record in a table

I'm trying to understand and get hold of the $wpdb global object but can't seem to make it work. Basically, I'm trying to insert a single record into a custom table in wordpress DB. Instead of ...
0
votes
0answers
32 views

Any issues changing username from wpdb in admin

I'm building a plugin that will have a custom sign up process built in. I would like the users to be able to change their username if needed, since I am using their email address as the username. I ...
0
votes
1answer
142 views

I'm not able to get access to $wpdb [duplicate]

I'm developing some additional functionality with a jQuery autocomplete form, some custom database tables, and PHP to query the tables. I have it working outside of the WordPress framework using ...
0
votes
1answer
436 views

$wpdb->insert Giving duplicates

I'm getting duplicate entries with this, how can I fix it please? <?php echo "Month". $_POST["Month"]; global $wpdb; $wpdb->show_errors(); $wpdb->print_error(); $wpdb->insert( ...
1
vote
0answers
37 views

Allow user role “salesman” to view only “client” role users

I have created two new roles in my theme, salesman and client. I want, when "salesman" is logged in to be able to view and edit only "client" users. I am trying this code (taken from an answer in this ...
1
vote
1answer
281 views

Form Shortcode not saving data to WP database

I'm developing a plugin that creates a custom table upon plugin activation. The plugin allows users to add a form shortcode to collect data for leads. I've got to the point where either the data ...
0
votes
0answers
112 views

Wordpress plugin tables become corrupt

I have written a plugin that creates and uses 3 database tables. On rare occasion, all 3 database tables become corrupt but no other tables in the database exhibit similar conditions. It is pretty ...
0
votes
2answers
309 views

WPDB SQL query with prepare() returning variable, not db value

I have been trying to get this to work for awhile now and I cannot seem to get any farther on my own. It seems to work fine as a normal SQL query but not within the WP framework using prepare(). ...
0
votes
1answer
32 views

query a newly created table using $wpdb

i created a new table inside my wordpress database called forms, this table consist of ID and names i want to query all the list from this table using the wordpress $wpdb this is my code below ...
0
votes
1answer
80 views

wpdb_prepare with multiple or condition

I want to execute a query like this: $wpdb->prepare( "SELECT * ... from ... WHERE ( post_title LIKE '%%%s%%' or post_content LIKE '%%%s%%' )..., $string ); If I do the query with only one ...
0
votes
1answer
66 views

Run “get_the_post_thumbnail” with a different table prefix?

I have this site were I run two Wordpress sites on the same database (with different prefixes), on one domain. What I want is to get the post thumbnail from the second Wordpress installation, by ...
0
votes
1answer
147 views

Creating Tables in WordPress Database

I'm planning to make a database for my wordpress website. It is to store (and retrieve) information about the products the members want to sell. As far as i understand, i have to make the tables in ...
1
vote
0answers
152 views

Wordpress running SQL query to update database from form

Basically I want to take information in from a form and use a separate php page to update the database. so here is the original wordpress php page (add_person.php): <?php /* Template Name: ...
1
vote
1answer
397 views

Error on inserting a form value to database

hi i have decided to store few values in a separate table, So i created it and now i used a form to store values but when i process that form i'm getting error Trying to get property of non-object and ...
1
vote
1answer
2k views

How to create database table, add data, update and delete using wpdb via plugins?

I am just starting out to create plugins with database. I know to create a custom database when activating the plugin. I just want to know whether we can create tables at the front end like adding the ...
0
votes
3answers
512 views

How to Modify this $wpdb query to accept an array of post statuses

I'm using this function from this accepted answer, which gets all values for a custom field key (cross-post). How could it be modified to allow an array of post statuses? function get_meta_values( ...
1
vote
4answers
6k views

get_results using wpdb

im trying to retrieve information on my wordpress database, i wanted to display all pages using this statement. but im getting a blank ARRAY global $wpdb; $result = $wpdb->get_results ( " ...
0
votes
0answers
90 views

esc_sql inserting weird chars to DB

I am using esc_sql function for making safer SQL operations but i am mysteriously getting ? and &nbsp; in the DB table how can i avoid them. Edit : Here is my array after esc_sql() Array ( ...
-1
votes
1answer
38 views

get only 1 wpdb and get taxonomy, post to next page [closed]

1st question. $passport_num="M00093"; $querystr = " SELECT $wpdb->posts.* FROM $wpdb->posts, $wpdb->postmeta WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id AND ...
2
votes
2answers
2k views

How to print the excuted sql right after its execution

I am searching for a way by which i can print the executed sql query just after the : $wpdb->query( $wpdb->prepare("INSERT INTO tbl_watchprosite ...
-2
votes
1answer
70 views

How to add wordpress pagination [closed]

i must use pagination. Where can i found good tutorial? $wpdb->get_results("SELECT * FROM wp_ogloszenia_kupione WHERE klient_id = $current_user->ID");
4
votes
0answers
252 views

WordPress database error: [Query was empty] [closed]

I'm using $wpdb to connect to a different database than my WordPress one like this: $newdb = new wpdb(DB_NEW_USER, DB_NEW_PASSWORD, DB_NEW_NAME, DB_NEW_HOST); I need to insert multiple rows into ...
0
votes
2answers
2k views

Using $wpdb to query posts with meta value containing current post_id

I am trying to to use $wpdb to retrieve a list of posts from the Database where the meta_value in the wp_postmeta table contains the current post_ID in inverted commas. eg. "10" The inverted commas ...
0
votes
0answers
99 views

Displaying posts from last 24 hours in current category with pagination

I am trying to find a solution for this problem but unfortunately without any success. I've checked WordPress Codex (WP_Query & wpdb) and few other solutions from Internet and still I wasn't even ...
1
vote
2answers
51 views

Make one query for adding entries to database

I have a situation where I need several entries to be added to a database table (sometime a few hundred), but using $wpdb->insert() (and $wpdb->update() where edits are necessary) is running ...
1
vote
2answers
456 views

create drop down menu in theme customizer from custom db

what i am trying to do is create drop down menu in theme customizer from custom db i have created. db name "students". in the db i have only the id and the name. i want to show all students names in ...
0
votes
1answer
508 views

Call to a member function get_row() on a non-object, Unable to use global $wbdp inside a plugin

I am building a custom plugin for my WordPress site. I made a php file called "checkrank" that obtains data from a custom table named "cranking". $uid = $GET['id']; function checkExists($id){ ...
0
votes
2answers
45 views

Mixing variables into an array when inserting values

I have a function that inserts a load of values into a database. Not a problem but I have a condition that changes the mysql statement. The problem is is the way wordpress constructs the statement, ...
0
votes
1answer
293 views

$wpdb->get_col and ORDER BY?

this is the query that returns the listing of a custom post type $apartments = $wpdb->get_col( " SELECT DISTINCT( post_id ) FROM $wpdb->postmeta ...
1
vote
1answer
1k views

using $wpdb to get custom post type with term

I'm trying to get the title of the first custom post type with a specific term in a taxonomy. But I'm not great at SQL so therefor not great with using $wpdb. Here is my code: $posts = ...
0
votes
2answers
1k views

Inserting into data into external DB using WPDB

I'm trying to work with an external db in Wordpress for the first time and can't seem to get it to insert the data into the DB. Here's what I have: <?php global $wpdb; $url = ...
0
votes
1answer
76 views

Adapting plugin for custom post type?

I am trying to reformulate a function (in a plugin) so that it applies to posts in a custom post type rather than normal posts. function saving_posts($post_id) { global $wpdb, $user_ID; ...
0
votes
2answers
2k views

Getting value from database table depending on field value

I am using a plugin called formidable which is similar to Gravity Forms in terms of purpose. I have two fields of interest. The first field loads up all the values in the Town column of my ...
-1
votes
2answers
1k views

Can't pass variable in wordpress wpdb->get_results

I wanna pass a variable, but always get the error message Invalid argument supplied for foreach()... Here is my code: function second($taxonomies) { global $wpdb; $result = ...
1
vote
0answers
47 views

Sorting main query by custom taxonomy slug

Is there a way to sort posts by custom taxonomy (shoe_color) ASC|DESC? I would like to do this using query_posts and passing the orderby=shoe_color into it. Here is the code I'm trying to work out: ...
-1
votes
1answer
53 views

How to get one result using wpdb class?

function asec_get_link_color() { global $wpdp; $query = "SELECT value FROM wp_theme_options WHERE property = 'link-color'"; $result = $wpdb->get_results($sql); return $result; } ...
0
votes
1answer
103 views

Custom Query for searching through custom fields

Just wondered if someone could spare 5 mins to help me understand where I might be going wrong. I have a set of custom fields for jobs - I would like to create two drop down menus as a quick search: ...
0
votes
1answer
78 views

wp_Query with 4 post meta feald arguments gives 500 internal server error

I am creating a custom plugin to search for custom post type provided with 4 meta field arguments. I am using wp_Query() to fetch the search results. My Query string is. $args = array( ...
3
votes
2answers
205 views

Search multiple meta keys at once

How would I modify the following SQL Query to allow me to search multiple meta keys at once? e.g. user_business AND user_about In the end I'll be searching about 40 - 50 different meta keys; or if ...
0
votes
1answer
63 views

WordPress Mysql query and Duplicate

i've a problem with mysql query on my wordpress database. I've custom fields Country and City. At moment I have this query that show all the cities of "UK" Country $querystr = " SELECT wposts.* ...
0
votes
2answers
108 views

$wpdb is queried but results don't show

I am trying to show a list of custom post types on a page template. When I view the page, instead of seeing the different posts, I see the actual page repeated. For example, If I have 5 posts, the ...
1
vote
1answer
211 views

Correct way to perform non-cacheable DB query

Consider the code function getNow() { global $wpdb; $now = $wpdb->get_var("SELECT NOW()"); $wpdb->flush(); return $now; } I am using the above method to avoid caching ...
0
votes
1answer
48 views

select a single val though a table in wordpress

The table is like this: category_id category_name category_parent_name I would like to get category_id by using category_name. I searched online, and the code is like below: $ad_cat is the ...
2
votes
2answers
606 views

How to programatically change username (user_login)?

As in the title, how to programatically change user's login? I wanted to use wp_inser_user function, but it appears that when updating current user, it doesn't change his/hers username. Should I use ...