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

learn more… | top users | synonyms

0
votes
5answers
108 views

Cannot access the thumbnails of attachment images… Cannot find the reason

I have a custom form that allows users to make posts and also upload images with it. The images are saved in wp_posts as post_type = attachment with a guid to show the image. Now I have created a ...
0
votes
1answer
35 views

How To Use WP_Query To Get The Custom Post type Posts With Keywords

I want to query with keywords and display some related posts on custom taxonomy page, the related posts comes from a custom post type "gift". I have tried the code below, but it only worked for ...
0
votes
1answer
15 views

Filter authors on meta value

I have added a section to my user profiles called ArtistCategory. This can be value X or Z. I'm using the code below to get a list, which I use in a menu and show after the artists display_name the ...
0
votes
1answer
47 views

DBDelta: “table doesn't exist” for a table that was just created

When I run the following code: global $wpdb; require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); $table_tags = $wpdb->prefix . "tags_tb"; $sql = "CREATE TABLE $table_tags ( ...
0
votes
0answers
24 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
1answer
62 views

Data inserted by wpdb insert is different than data pressnt in database.

I have made this insert query: $insertsuccess = $wpdb->insert( 'compservices', array( 'orderId'=> $orderID, 'orderedTime' => $date, 'useremail' =&...
0
votes
1answer
38 views

$wpdb query for price in custom field value

A classifieds list site have only 3 criterias when searching products: the common search, category and region (for ZIP, city or full address) It's not enough and I really need to include a basic price ...
0
votes
1answer
29 views

Include post_status check within $wpdb query

I've got a function that returns a count from the database for publish posts that match the product ID to the post meta ID (both are the product type). I've realized this query returns unpublished ...
0
votes
0answers
23 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" required>&...
1
vote
0answers
33 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 (118,117,116,...
2
votes
1answer
50 views

WPDB Multiple site's posts and get featured images

I am using the code below to query 5 Wordpress sites for their posts, merging them into an array, sorting the array by date, and then displaying them: //SITE 1 $mydb = new wpdb('xxxx','xxxx','xxxx','...
1
vote
0answers
46 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 ...
0
votes
0answers
20 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 ...
1
vote
2answers
46 views

Wordpress SQL Issue not returning correct reselts

So, I have been working on an SQL query involving the users and usermeta tables in wordpress. I am not getting the correct results. I have the following query written SELECT * FROM ...
1
vote
2answers
64 views

$wpdb select all meta for each post

I'm running the following query trying to get the data and associated meta data of a huge number of posts: SELECT wp_posts.post_title, wp_posts.post_date, wp_posts.ID, wp_postmeta.post_id, ...
0
votes
2answers
36 views

wpdb get_row database query inquiry

Is this the right way to use get_row with a select *? $_crds = $wpdb->get_row($wpdb->prepare(" SELECT * FROM `mailers` WHERE `id` = %d", $_GET['caId'] )); $_zipcodes = $_crds->zipcodes; $...
0
votes
0answers
130 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 Leggings;http://nlyscandinavia.scene7.com/is/image/nlyscandinavia/...
0
votes
1answer
39 views

Does WordPress $wpdb functions wait when table is locked?

Does WordPress' $wpdb functions wait when the table is locked? For example Function A() uses $wpdb->getresults. When $wpdb->getresults wants to read a table and its locked, does it wait for ...
0
votes
0answers
14 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
54 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
1answer
119 views

wpdb get_results() returns only 2 rows

I am trying to create custom admin widget to present how many users has registered within last days. I have created function as below: function mdbootstrap_add_dashboard_recent_users(){ global $wpdb;...
0
votes
1answer
79 views

WPDB - Read and write value from / to database

I have a custom field in usermeta called vatnumber. If the field has a value, how do I read that specific value for user X? Here's what I have so far: <tr class="vatnumber"> <th><?...
0
votes
0answers
66 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
2answers
74 views

Missing argument 2 for wpdb::prepare() [duplicate]

I am working on a website that uses a previously developed image slider plugin. I had it all working in my local environment but once I took it live it kicked the following error anywhere the image ...
0
votes
1answer
97 views

WP Database Table to CSV file

I'm working on creating a script that takes a custom WordPress database table and exports it into a CSV file. I cannot seem to get it to work. Can someone help me out <?php $parse_uri = explode( '...
4
votes
1answer
75 views

How to define composite keys with dbDelta()

I am getting error while trying to create a table with dbDelta() and composite primary key. The sql is pretty straight forward. $sql = "CREATE TABLE {$wpdb->prefix}voicemail_call ( user_id ...
0
votes
1answer
80 views

Dynamic URL, not a physical page within the database

Knowing how WordPress essentially processes page requests (through index.php and .htaccess), I'm trying to figure out the best way to "ignore" a certain permalink structure, or rewrite it in such way ...
1
vote
1answer
51 views

Getting id of poll from WP database

So I have a php statement: $latest_pollsid that contains a number which increases by 1 every time a specific form is submitted. I am reading this statement into several functions and for one of these ...
0
votes
4answers
87 views

wp_posts table: safely remove unused columns to save database storage

i search about it on google but didn't find any thing. I want to remove my wordpress wp_posts table's unused columns, to save my database storage... I know if table column is empty it will not ...
0
votes
1answer
46 views

Proper Prepare Statement for ALTER TABLE and using AFTER

My code for ALTER TABLE doesn't make use of the prepare() method of $wpdb and so the code needs to be updated properly. There are plenty of examples of query SELECT, etc but couldn't find something ...
1
vote
1answer
94 views

Custom Post Type + 20k posts = blank/404 within Admin edit.php [duplicate]

I have registered a custom Post Type via register_post_type(), and about 45 Custom Fields via add_meta_box() function, within the theme. Custom Post Type Args: 'labels' => $labels,...
6
votes
1answer
56 views

Multisite posts in categories on network

I'm running a multisite with a main site and 3 subsites (the number of subsites will be over 200 at the end). Now on every site I have a category called A, Category called B, and Category called C. On ...
0
votes
1answer
69 views

Custom Query - Based on user input

I'm working on displaying suggestions to an input, assisting the user. I'm using the included jQuery suggest. That's loading - and through ajax I'm using a custom SQL query and can see it's ...
1
vote
1answer
58 views

$wpdb to insert html form information

I'm trying to insert posted variables from a form. When I shorten the amount of variables I'm inserting it will sometime pass the information in my mysql database. Once I continue to add on ...
0
votes
3answers
390 views

MySQL query in Wordpress with AJAX

I have a search form which searches the DB and returns back some data. I have managed to use Wordpress wpdb to connect and use select statement on the table and retrieve data. Everything works fine.....
0
votes
0answers
15 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 ...
1
vote
1answer
22 views

External DB Connection [closed]

I'm trying to connect and select some data from an external DB. The DB is in the same server as WP, so it has the same username and password, but different DB name. Here's what I'm using to connect to ...
3
votes
1answer
82 views

Converting mysql to $wpdb

I'm trying to convert this to using a $wpdb class. It will return all the enums possible and i have to use this $wpdb due to mysql_query giving me weird error (no database selected) Code is following ...
1
vote
1answer
89 views

Database: Custom table: sprintf value for DateTime column

I am creating an insert query following the insert example on the wpdb class reference. What sprintf like placeholder should be used for a DateTime column on a custom table? Allowed placeholders seem ...
1
vote
0answers
104 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' => $...
0
votes
2answers
103 views

Custom query: Get all posts that are from a certain category?

This is what I have: global $wpdb, $month; $months = $wpdb->get_results( "SELECT * FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish' AND DATE_FORMAT( ...
0
votes
1answer
120 views

How to insert dash (-) into database using wpdb and new_to_publish hook?

I am saving titles of posts in a separate table for a specific use. The titles are saved to the database when a post is published. code is: add_action('future_to_publish', 'send_emails_on_new_event');...
1
vote
1answer
25 views

How to prevent $wpdb->prepare stripping a leading zero in variable value?

I have a simple database_read function and per accident I noticed order_id's starting with a leading zero would not give me the expected results. It turns out using $wpdb->prepare strips out ...
0
votes
2answers
174 views

$wpdb-prepare : Do I have to bind a parameter to the table name?

I only do a SELECT on a whole table - and the table is defined in a variable: $table = $wpdb->prefix . 'members'; Do I have to bind a parameter to this variable? This caused an error: $result =...
0
votes
1answer
66 views

Using “->” in a page to exceute $wpdb query gives error

I am doing some SQL queries in a WordPress page using the Insert PHP plugin, but the -> object operator changes to -&gt; when I write code in the Text editor, or view in the Visual editor. When ...
0
votes
1answer
457 views

Inserting Post Meta From SQL

I'm trying to get post meta to be updated/replaced with $wpdb and running into issues. I have working SQL, but cannot get it work when coding it up for my WP plugin. Extra note: The post meta being ...
0
votes
1answer
27 views

Depreciated Call -> Function wpdb::escape()

I am getting lots of errors in my debug log: Depreciated Call -> Function wpdb::escape() - Use wpdb::prepare() or esc_sql() instead Instead of just turning off the debug log, I am trying to "...
1
vote
3answers
143 views

How to Download and install plugin database remotely

I have the following problem. I got a plugin that is huge due to all the data needed. The data is all the countries and cities in the world and also a maxmind.mmdb database. 1 - Issue Currently I ...
0
votes
1answer
151 views

Why is an empty result an error? ( $wpdb->get_row )

I have a query where I get the highest id from a table. $user_id = $wpdb->get_row("SELECT * FROM $table WHERE id=(SELECT MAX(id) FROM $table)") The table should always have rows, but if for ...
0
votes
0answers
23 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 ...