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
17 views

Issue regarding $wpdb->prepare()

$wpdb->prepare() is adding single quote ('') like below. I am using below code $sql = $wpdb->prepare("SELECT * FROM %s ",$table_name); echo $sql; I am getting output like below SELECT * FROM ...
0
votes
1answer
18 views

How to add next height number in Order Attributes inside the Add new page. [duplicate]

By default, when a new page is added it will be given the next highest number not already assigned to a page.
0
votes
0answers
17 views

sanitize_text_field and apostrophe problem

I've written a custom plugin to send data via a form to a personal database, different from the WP one. Everything is working fine except the fact that when you write a name, for example D'ALESSANDRO, ...
0
votes
2answers
45 views

Optimising amount of calls to custom fields

I have this code fragment in my codebase: foreach($this->adverisers as $adveriser) { $this->data[$adveriser->name]['image'] = bfi_thumb(get_post_meta($adveriser->ID, ...
0
votes
0answers
16 views

Save customizer default values to DB on theme activation

i am working with multisite. each time i activate some theme in new blog, i need to go to customizer and click the "save" to save all the values to db so i could use the with get_theme_mod if there ...
0
votes
1answer
29 views

How to get DB options format without saving? [closed]

Using Unyson framework. I am getting theme options form data saved to a file. Was able to do that via ajax and JSON.stringify(form values in json format) problem I have is that the form data ...
1
vote
1answer
32 views

WSoD being caused by this piece of code

This is a function I'm writing which is supposed to post an input along with some other information, to a database. As of right now, activating the plugin produces a WSoD, when the function is removed ...
1
vote
1answer
17 views

Avoiding “Usage of a direct database call is discouraged”

WordPress-Coding-Standards reports that "Usage of a direct database call is discouraged." It's complaining about my usage of $wpdb->insert() in a plugin. Is this not recommended? What is the ...
0
votes
0answers
32 views

API to push post data to WordPress and populate custom fields

I've been looking around for related posts and such in the codex and other Q&A sites for several hours now, but haven't really come up with much so I thought I'd ask all you fine people out there ...
1
vote
1answer
31 views

Get data from database using $WPDB

I'm missing something here. I simply want to get data from my database. So I tried this but keeps giving me an error. global $wpdb; $sql = "SELECT * FROM $wpdb->postmeta WHERE group='$group'"; ...
0
votes
1answer
18 views

How to Generate a list of Most Commented post?

I'm trying to call a list of most commented post. But the call to the DB returns always the same post (the first one in the loop) This is my code in functions.php function ...
1
vote
0answers
14 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 ...
0
votes
1answer
22 views

Plugin with connection to database - Single function

I'm creating a personal plugin with more files and I need to connect to an external database with WPDB. At the moment I'm repeating "new wpdb(...)" in every function, in every file, of my plugin. Is ...
0
votes
2answers
35 views

Ajax insert or update data

I've been browsing through similar questions and have yet to get this functionality to work. I'm tracking the progress a user makes an embedded vimeo video and insert data or update data. JS on the ...
0
votes
0answers
15 views

$wpdb->insert running multiple times?

Im trying to run a $wpdb->insert ONCE on every page load (for testing purposes). The insert will insert a meta field for a post type. I have tried hooking the insert function into "init", add it to ...
0
votes
0answers
12 views

get_results is not working properly

I tried to find an answer in many forums for this problem, but it has been impossible. My problem is that when I do $wpdb->get_results in an empty table, mi webpage immediately stops working. ...
0
votes
1answer
25 views

Plugin will sort users by usermeta

As I refine my most popular plugin it will store a special number decoded from the user's birth date, which is an extended BuddyPress field in bp_xprofile_data. All users get a number between 1 and ...
5
votes
1answer
105 views

WordPress and multithreading

I'm working on a plugin. I've created an API that reads and writes to a custom table in the DB. This API can be called potentially from N clients simultaneously (and it really happens). I noticed that ...
0
votes
1answer
29 views

Alter the main search query to search posts by coauthor user name

I am using the Coauthors plugin: https://wordpress.org/plugins/co-authors-plus/ I have written some SQL in order to grab posts from authors whose display name matches the search query when searching ...
0
votes
1answer
38 views

Fixing wpdb->get_results and wpdb->prepare?

So I have been using the theme Vilan from ThemeForest. Along with the theme come a couple of plugins, of which one is Revolution Slider. I'm also using Bedrock by Roots. I'm getting the following ...
0
votes
1answer
30 views

Run posts_where and posts_join only on the main query

Using the pre_get_posts hook, I'm able to take $query as an argument. But on posts_where and posts_join hook, I receive the respective clauses and not the query. The problem is that the hook is ...
0
votes
1answer
5 views

Creates only one table and not the other

I have this function to create two tables when I activate the plugin. Only the wp_wpt_stats table are being created and not the wp_wpt_list. I know the dbdelta is picky, but I can't see what I'm doing ...
0
votes
0answers
21 views

Ordering list of users by last name and then by first name

I have a page listing users with certain custom roles, ordered by last name in alphabetical order. So far, so good. The problem is when two users have the same last name (i.e. John Doe and Rick Doe). ...
0
votes
1answer
25 views

WPDB Table Does Not Exist

From this code: global $wpdb; $sidebar_table = $wpdb->prefix . 'w3care_sidebar_position'; $checkad = $wpdb->get_results( $wpdb->prepare( "SELECT ad_id, sidebar_position, ad_type FROM `%s` ...
0
votes
1answer
40 views

Wordpress Insert not working with ajax

I am trying to enter insert data with form in wordpress and want to use ajax for that. Without ajax it works fine but when I use ajax pressing the submit button gives 0 in result and the data is not ...
0
votes
0answers
36 views

Query postmeta values, and return multiple post_titles for common meta value

As of now I query the DB: global $wpdb; $query = $wpdb->prepare(' SELECT p.post_id, p.meta_value, pm.post_title FROM %1$s AS p JOIN %2$s AS pm ON ...
1
vote
2answers
64 views

$wpdb->replace / Replace or update primary key

I write code to save data in to the database table. I want Replace a row in a table if it exists or insert a new row in a table if the row did not already exist. ...
1
vote
1answer
19 views

How does the WXR file differ from the WPDB?

I'm looking to make it so an administrator can do a complete backup of a WordPress website with the click of a button in the administration pages. In doing so, I figure the code would need to backup ...
0
votes
1answer
25 views

Query Custom Fields in Searchform

In my searchform.php I want to query the values of a custom field, add them into a dropdown, and return a link to a corresponding page upon submit. Thus far I can create the values dropdown: global ...
1
vote
1answer
23 views

Why $wpdb->show_errors() and print_error() is showing an output even if the query output is correct?

In order of figuring out the following issue, see Sanitize a working query string by using $wpdb->prepare() fails with MySQL DB error "right syntax to use near '3' at line 1" i ...
0
votes
0answers
85 views

Ajax Form data is not posted back to the get_results()

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 ...
0
votes
0answers
42 views

Sanitize a working query string by using $wpdb->prepare() fails with MySQL DB error “right syntax to use near '3' at line 1”

I was using the following properly working query so far: $querystr = " SELECT wposts.* FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta1, $wpdb->postmeta wpostmeta2 WHERE wposts.ID ...
0
votes
1answer
35 views

Ajax Query returns zero

I am doing simple wordpress select query and want to do this with ajax jquery and do not want the page to refresh when I press search button and writing text in search textbox. As soon as I press ...
0
votes
1answer
42 views

Search query with Ajax

I'm running a $wpdb select query and getting it’s parameter from a textbox. Result shows as soon as I press the search button, but I want to do the same with Ajax without refreshing the page. I have ...
0
votes
0answers
34 views

Update all fields of table with ON DUPLICATE KEY UPDATE command

I write code with $wpdb->insert command into the database table wp_coin_price. After inserting data in the table, I write code to update all fields with ON DUPLICATE KEY UPDATE, but it's not ...
0
votes
2answers
50 views

$wpdb->query can't insert data

I Write Code to Save data in the Wordpress database table (table name is wp_fafa) But Can't Save data in $qry = $wpdb->query( "INSERT INTO `wp_fafa` ...
0
votes
1answer
15 views

Why won't this wpdb get_results query return results?

Having trouble with this query. It returns an empty array even though I know the variables are correct and that multiple rows exist in the database that match. $results_a = $wpdb->get_results( ...
0
votes
0answers
33 views

Using $wpdb (WPDB class) 'replace' with multiple WHERE criteria problem

I have two fields that are used to identify a particular row (acting as a composite key). If it does not exist, I wish to insert a new row. The REPLACE function ...
0
votes
1answer
18 views

WPDB for post count on post

I figured out how to show the count of a custom post type on author.php . I am trying to display the stats on their custom post as well. The same query does not work. How can I show the amount of ...
0
votes
1answer
23 views

MySQL queries in Wordpress

I have a MySQL database table called stock which holds a stock record on items for sale. When querying the database using PHP I have no issue, but when I try to do it through WordPress it doesn't ...
0
votes
2answers
50 views

Shared Custom post type between WP network sites

I'm developing four websites which are separate, besides the Events (custom post type). Three of the websites are WP, and I've got them in a Network. I would like Events to show up in all three Admin ...
0
votes
0answers
50 views

wpdb query using duplicate key to check update/insert

I am trying to use the query below to insert a row into my wp_postmeta table. If this row exists already e.g the meta_id key is not unique I need it to update this row with the meta_value at the end ...
3
votes
2answers
111 views

Return only Count from a wp_query request?

Is it possible with the standard build-in tools in Wordpress to get wp_query to only return the count of an query? Right now, I’ve a query which has several meta_queries but what the only thing I’m ...
0
votes
0answers
32 views

Created a function similar to facebook events with [ Attending / Not attending ] options

I modified and extended an event plugin on wordpress that is being hosted on GITHUB then finally came up with this idea in a separate PHP file and added options such as the ATTENDING and NOT ATTENDING ...
0
votes
0answers
12 views

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

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 ...
0
votes
2answers
50 views

Displaying data from another database

I'm working on custom plugin that will pull property information from our non-wordpress database. That is working just fine. Where I'm having problems is getting the whole front end piece to work. ...
0
votes
1answer
58 views

Protect custom form from SQL injection

I'm trying to understand how to protect my custom form from possible attacks. I send a data via a form, let's say userdata, then I read it: $userdata = $_POST['userdata'] I put it into an array to ...
0
votes
0answers
32 views

why nl2br() is adding an extra <br>?

I store the text with wpdb->insert. While retrieving it with wpdb->get_results I echo it with nl2br() function to preserve the new lines (or it will be echoed without line breks). Problem is ...
0
votes
1answer
24 views

Retrieve a list of users based on some conditions

What am I doing wrong on this query? The main issue is the var_dump returns null. The query works fine in phpMyAdmin. global $wpdb; $users = $wpdb->get_results( $wpdb->prepare( ...
0
votes
1answer
22 views

Write mysql credentials in plugin

I've to create a custom plugin to print data from a database different from the wordpress one. I'm using wpdb. Is it fine, from a security point, to write database credantials in the plugin files in ...