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

learn more… | top users | synonyms

2
votes
0answers
1k views

$wpdb->get_results(…) returns empty array despite correct query

As title implies, I cannot seem to get $wpdb->get_results to give results. Running the "raw" query is successful, but this seems to be failing for some strange unknown reason. global $wpdb; ...
2
votes
0answers
344 views

post_content getting cut off on blank space on $wpdb->update

I am publishing the following post via xmlrpc <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html><head><meta ...
1
vote
0answers
21 views

Connect to separate database using $wpdb and authenticate user

Have a couple questions. Just to get everyone up to date: I had created a new file wp-custom-config.php Use define define( 'NEW_HOST', host name); and other details. And add code for DB connect like ...
1
vote
0answers
30 views

How to translate this mySQL query to $wpdb query

I'm having trouble recreating a query from straight mySQL to $wpdb compatible. SELECT meta_value FROM `wp_postmeta` WHERE meta_key = 'review_rating' AND meta_value = 5 AND post_id IN ...
1
vote
0answers
33 views

Optimizing Wordpress Queries - Removing Group By ID

I'm looking to transform a few queries that I'm running through get_posts into direct MySQL queries, in the hopes of optimizing them further. I see that my initial get_posts query, once built and ...
1
vote
0answers
76 views

Proper usage of $wpdb->update()?

I am trying to update my custom table in Wordpress using the following php code but still no success: $tablename = "wpfeedback"; $data = array( 'mark' => $mark, 'comment' => ...
1
vote
0answers
135 views

Create a table with wordpress plugin boilerplate

I am a new wordpress developer and i would like to create my first wordpress plugin based to wp plugin boilerplate template plugin. My plugin will have to do with my clients data so for this reason i ...
1
vote
0answers
474 views

I am getting allowed memory exhausted in wp-db.php

Today I checked my error_log and found these errors in it. PHP Fatal error: Allowed memory size of 176160768 bytes exhausted (tried to allocate 5290845 bytes) in ...
1
vote
0answers
71 views

Using $wpdb to fetch posts with meta data

I have a post type "shows" with 500 posts in it. I want to list all 400 in one page listing their title + 5 meta fields and a url to the show post thumbnail. I initially went the classic wordpress ...
1
vote
0answers
58 views

Codex: Database Description: meaning of Cardinality

The following post outlines how to word cardinality is commonly used when dealing with databases: http://stackoverflow.com/questions/10621077/what-is-cardinality-in-databases. However I have not been ...
1
vote
0answers
261 views

wpdb custom tables without plugin

I am using custom tables, with $wpdb, trying to perform basic queries at the moment. I can't find anything on manually creating tables then using them with $wpdb, everything is plugin related. I ...
1
vote
0answers
104 views

How to query custom post types with mixed AND & OR statements for custom fields

I have a custom post type "events" which includes the custom fields "is_premium" (which is a true/false) and "premium_expiry_date" which is a date picker. On my front end, I want to have "events" ...
1
vote
0answers
813 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 ...
1
vote
0answers
46 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
0answers
390 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
0answers
57 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
vote
0answers
151 views

Changing status of Published posts which have less Content to “Draft”

function draftpost(){ global $wpdb; $prefix = $wpdb->prefix; $wpdb->query("UPDATE ".$prefix."posts SET post_status='draft' WHERE LENGTH( post_content ) <500"); } ...
1
vote
0answers
1k views

$wpdb->get_results() returns good result only in first foreach iteration

I've got strange issue when I am using $wpdb->get_results() in content-single.php in Twenty Eleven theme. $wpdb->get_results() returns proper values only in first loop iteration. I've got simple ...
1
vote
0answers
36 views

Code only works every other time its run

This code below works fine as long as I leave the $wpdb query commented out. However, I'm trying to clear the current settings before I write the new ones into the db. That's the purpose of the $wpdb ...
1
vote
0answers
231 views

Query most popular terms by taxonomy over 2 week period

I have written SQL for a query that pulls the most used taxonomy terms for selected taxonomies that are published, do not have a parent post are not in a comma separated list over the past two weeks ...
1
vote
0answers
229 views

wpdb updating record in wordpress with json adds extra array elements

This is killing me - I keep getting magical array elements added to my updated array in WP. For example if my query is (var_dumped below): string(70) "UPDATE wp_mytable SET already_played = '[9]' ...
1
vote
0answers
246 views

How to display users with posts published between two dates (Sorted by Post-Count) [Multisite]

I'm trying to make a list of users who have published posts within two given dates. My attempts using WP_User_query just work for one blog ID and takes time to load because it runs through a lot of ...
0
votes
0answers
16 views

Custom database query with accents returning no results

I have an issue where using accents in my custom database query (wpdb) returns no results. $wpdb->get_results( "SELECT * FROM table WHERE city = 'Montréal'" ); Returns nothing, while ...
0
votes
0answers
16 views

Use $wpdb->get_results with filter based on array

I need to filter my SQL query (in a plugin) based on an array of meta_values. I have CPT-A which is related to CPT-B. I am keeping an array of CPT-A ids in meta_key afz_entry_tags of CPT-B I need ...
0
votes
0answers
21 views

Limit results of custom query to current category

I have created a geolocation system for a custom post type of services and have been working on a query to limit the results based on address/distance entered by the user. Everything seems to be ...
0
votes
0answers
19 views

update query wordpress plugin

I am trying to update data in wp table. However, data is not updated. This is what I've tried. Here , $eadate is DATE , $estime is time in HH:mm:ii format. <?php global $wpdb; if ...
0
votes
0answers
17 views

Why Do I Still Getting Duplicate Rows in SQL?

I'm creating a Custom Freight System which stores the order and the products requested by the user into the WordPress Database. The Problem When I insert the product into the wp_my_custom_products ...
0
votes
0answers
30 views

Change MySQL PDO connection to a WPDB connection

So I have an autofill search box with a PHP script that gets data from the DB. It uses a PDO connection, and it works perfectly even with my Wordpress Database, but since I'm not sure of how PDO ...
0
votes
0answers
25 views

WordPress database error:

Thank you in advanced for any help on this issue. I have this query: $query = $wpdb->update($tablename, array( 'student_first_name' => ...
0
votes
0answers
23 views

Trying to write a count function for a custom db query

I'm trying to tally results from a column in my dp for specific intervals (i.e. one day, two, etc..) I'm not a coder by any means, I've got the query down okay but can't get num_rows to work and then ...
0
votes
0answers
22 views

log in form using a separate database

in the html code i have made this form: <form action="http://www.mySite.co/login.php" method="post"> <fieldset> <p><input type="text" name="uname" placeholder="Name" ...
0
votes
0answers
19 views

Processing a lot of $wpdb isn't insert all the data

In my plugin the user provides some CSV files that are processed and either inserted or updated based on a sku (which acts as a foreign key to my DB and a primary key for where the CSV comes from). I ...
0
votes
0answers
69 views

Wpdb insert with special characters

I am facing a strange issue with insert query using $wpdb. I am trying to insert a record below (a row from a CSV file): Plenty Denim ...
0
votes
0answers
12 views

WordPress Plugin error: Multiple primary key defined

Given an SQL statement like this to fire on plugin activation: $charset_collate = $wpdb->get_charset_collate(); $sql_fields = "CREATE TABLE wp_my_table ( id int(11) NOT NULL AUTO_INCREMENT, ...
0
votes
0answers
34 views

Convert $wpdb to WP_Query()

I have the code below which I would like to change into a WP_Query so that I can easily filter posts by taxonomies. I am having trouble understanding how I would add get_posts_by_author_sql( ...
0
votes
0answers
44 views

Can't Install WordPress (local) Failed to open file wp-includes/wp-db.php

Title kinda says it all. Trying to install WP locally and I get the following error when trying to use the wp-config.php generator UI: Warning: mysqli_real_connect(): (HY000/2002): No such file or ...
0
votes
0answers
13 views

Unique user tables between three sites with same database

I have three websites that have their own prefixes, but are in the same database and have each member, and I have create a system that would allow to confine all its members in a mime table, so to ...
0
votes
0answers
19 views

Private Messages between users

I'm RoR programmer but for sometime I play with WordPress. My problem in RoR wouldn't even exist and here I don't know what to do... I create table wp_wr_messages with all needed fields. I ...
0
votes
0answers
46 views

Display result from custom post meta query

This is driving me crazy! I'm trying to simply echo the contents of a meta field (twitter) from the wp_postmeta table of a custom post type with the following query outside of the loop : global ...
0
votes
0answers
44 views

How to access PostgreSQL using WPDB?

I got a separate database using PostgreSQL and I want to access it via the WPDB class. I tried $pgdb = new wpdb('[username]','[password]','[database]','localhost'); var_dump( ...
0
votes
0answers
87 views

Querying custom tables using WP_Query

I am looking to extend the WP database by adding a custom table. I know how to do it using the $wpdb object; however, I have seen on some sites that it is better to use the WP_Query class, but I can't ...
0
votes
0answers
36 views

wpdb->update update the entire table instead of one row

I'm trying to use the update function of wpdb, like this: $wpdb->update( 'protocol_data_list', array( 'used' => 1 ), array( 'cod_protocollo' => $_POST['numero_protocollo'] ), ...
0
votes
0answers
67 views

Inserting PHP code snippet via shortcode

I'm trying to insert a PHP snippet on a WordPress page using XYZ Insert PHP Code Snippet plugin. This is the code that I'm using but it's not working and I can't figure out what's wrong. I've tried ...
0
votes
0answers
22 views

get_results no result back

I can't get a result back from this query...any suggestion? function per_match(){ global $wpdb; $myrows = $wpdb->get_results( "SELECT id FROM partite;"); foreach ($myrows as $myrow) { ...
0
votes
0answers
32 views

$wpdb global causing issues with plugin class

I am currently building a plugin. I have a main init.php file which loads all the necessary plugin classes. Within one of the classes, I have several methods that call the $wpdb global. One of the ...
0
votes
0answers
143 views

$wpdb->query(update) not working as supposed when passing GET request in the where clause

I have made a table 'wp_mostfavourite' in wordpress database, it has got three fields, 'serialno', 'postid', 'counts'. The 'counts' is supposed to be increased by 1, whenever the following query is ...
0
votes
0answers
52 views

Using $wpdb_update and foreach loop

I have this function to update data in my table list but it's not working. My insert and delete are working well, but I don't know what's wrong with this: function update_data() { global $wpdb; ...
0
votes
0answers
160 views

How to execute a SQL-query which contains multiple queries using $wpdb->query?

I want to execute the following Query-String, which contains 2 separate queries using $wpdb->query: CREATE TABLE `foobar` ( `id` int(2) NOT NULL AUTO_INCREMENT, `foo` varchar(22) COLLATE ...
0
votes
0answers
34 views

Querying same column twice with wpdb (for postmeta values, specifically latitude and longitude)

I've seen similar questions around, but I just can't apply them to my case, I'm quite new at this, apologies. I'm trying to create a google map of my posts, using a latitude and longitude that are ...
0
votes
0answers
160 views

$wpdb not working in file of WordPress plugin

I am working in WordPress plugin. I create a custom form where user add values and then click on submit button. When user click on submit button its redirect to custom process file, where i write ...