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

Combine WP_Query results with new WPDB->get_results Query

Is it possible to combine results from a WP_Query array with results from a new WPDB get_results() and use the loop to loop through the results? Essentially, I am trying to modify a shortcode that ...
-1
votes
0answers
9 views

Get all Woocommerce products where attribute value matches something

I would like to create a page where only custom-made products are listed. I created the is_custom custom attribute on all my products with two possible values: yes - no In my custom template I would ...
0
votes
0answers
13 views

wpdb->query and non-ASCII characters in given query

recently I'm dealing with wordpress and I find myself running a table creation query in a plugin through the function $wpdb->query (this wpdb class). Everything is fine until I put a non-ASCII ...
0
votes
1answer
13 views

Custom database query to validate data

I cant find any syntax for custom queries, use of $wpdb is new to me so can anyone help me solving this?? if(isset($_POST['submit'])) { global $wpdb; $tablename='wp_form_subscribe'; $myrows = ...
0
votes
1answer
37 views

Read post meta values, only if posts are public

I want to retrieve meta_values applied to posts. Currently I execute the following query global $wpdb; $table = $wpdb->prefix.'postmeta'; $values = $wpdb->get_results( "SELECT meta_value ...
0
votes
1answer
26 views

Get an array of meta_values for a user meta_key

I need to get an array of all the meta_values for a user meta_key. I found this code: $cities = $wpdb->get_col("SELECT meta_value FROM $wpdb->usermeta WHERE meta_key = 'my_cities_meta_key'" ); ...
0
votes
1answer
21 views

Function returning queried meta value based on current post ID

I have written several queries which sums download counts grouped by the post they are associated with, and other relations. They work great for exporting to CSV and other uses outside of WordPress, ...
0
votes
1answer
15 views

WPDB SQL Ignore `post_status` Parameter

I use this SQL statement: SELECT * FROM wp_posts LEFT JOIN wp_term_relationships ON ( wp_posts.ID = wp_term_relationships.object_id ) LEFT JOIN wp_term_taxonomy ON ( ...
0
votes
0answers
31 views

Custom post type as HTML/PHP table

I have a custom page which displays some WP members (students) using $wpdb to query the database and display these members in a HTML table. This table gets generated (populated with records) when the ...
0
votes
1answer
20 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
19 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
30 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
48 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
28 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
39 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
34 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
22 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
49 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
44 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
20 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
19 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
24 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
47 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
20 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
14 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
27 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
108 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
40 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
51 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
38 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
7 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
35 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
28 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
62 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
41 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
77 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
20 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
32 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
27 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
116 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
55 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
44 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
65 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
40 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
59 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
20 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
36 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
19 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
26 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
60 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 ...