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

How to choose the content from a post which is in the right category?

I have a shortcode, which contains the post title. This shortcode loads in the frontend the content from a post. Thats works fine: function title_content($atts, $content = null ) { global $wpdb; ...
6
votes
1answer
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; ...
0
votes
1answer
8 views

Create an array with a string key from wpdb->get_results

Using this code to get some data into a PHP array: $currentProducts = array(); $currentProducts = $wpdb->get_results("SELECT id, feedid, size, price FROM products WHERE shopid = $shopid"); No ...
0
votes
0answers
73 views

Change MySQL PDO connection to a WPDB connection

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 works, I'...
0
votes
1answer
499 views

WordPress get pagination on wpdb get_results

How do I gee the numbered pagination of custom wpdb result? below code will show one latest post from each authors in the site. I want to show 20 posts per page with a numbered pagination. $postids ...
0
votes
0answers
14 views

Call to a member function insert()

I did a POST form and try to sign in to the Wordpress database is showing this error. Fatal error: Call to a member function insert() on a non-object in C:\wamp\www\teste\wp-content\themes\...
0
votes
2answers
1k views

Use AJAX in a WordPress Plugin to Get Data From Custom Database?

I've created a PHP script that works great stand alone. I need to convert this script to a WordPress plugin. I've created a custom table in the WordPress database. When i try to get data back I get ...
0
votes
0answers
19 views

wpdb->prepare clarification

Is there anything wrong with using wpdb->prepare() to retrieve items from a custom database table? Note how I've used prepare() below, without passing the $type variable through prepare(). I just ...
3
votes
1answer
22 views

$wpdb->prepare not working with update table prefix

The following does not work with my custom table: $wpdb->prepare("UPDATE $wpdb->jch_gigs SET available = available - %d WHERE ID = %d", $quantity, $item) ); But this does: $wpdb->...
1
vote
2answers
657 views

Exclude subscriber users from user list

I want to exclude Subscribers from a user list. My code is: $users = $wpdb->get_results( "SELECT display_name FROM $wpdb->users ORDER BY display_name ASC" ); How can I change that so ...
0
votes
1answer
519 views

Delete query won't run

This is the set up: <form method="post" action=""> <input type="hidden" name="delete_app_id" id="delete_app_id" value='<?php echo $adoptee->app_id; ?>' /> <...
0
votes
1answer
823 views

Out of Memory - Line 791 of WP-DB.php (mysql_real_escape_string)

Update The end result is that I did not account for Apache memory limits. There were limits placed on the Apache process which caused PHP to be limited regardless of the settings placed on it. ...
0
votes
1answer
38 views

How to connect and insert data in database of wordpress?

On my website, there is a section called "My Ideal plank." It is a form where the user will enter their data and there will be a return message with the type of ideal board for the person. First ...
0
votes
1answer
822 views

How to insert image path in database to display product image in wp-admin?

In which database table and column do I need to insert an image path, in order to display product images in wp-admin (not on the front end)? I insert products by query in WordPress, rather than insert ...
0
votes
0answers
15 views

Trim data before insert?

Recently I use this syntax to input data like below: $STRING_DATA = StrToLower(Trim($input_data)); $wpdb->query ( $wpdb->prepare ( 'SQL SYNTAX WITH PARAMETER STRING', $STRING_DATA ) ); Do I ...
0
votes
1answer
2k views

Action hook “wp_insert_post” works but not for last imported post

I want to run a custom function whenever posts are imported to my custom post type. I am currently running this code - function on_post_import($post){ global $wpdb; $results = $wpdb->...
0
votes
1answer
734 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 ...
3
votes
1answer
557 views

Change post status based on meta value

I have this cron set up to trash posts x days after it is posted. This works. Edit: Added my answer to my question. add_action( 'wp', 'do_trash_ads' ); function do_trash_ads() { if ( ! ...
0
votes
2answers
5k views

Inserting data into custom tables

I am trying to create custom input tables to send data into custom tables on the wp database. I cannot get my script to do anything. The user will enter a type of liquor, like vodka or whiskey, ...
1
vote
1answer
738 views

$wpdb->get_results returns empty but value exists

this is my first question here. More then 5 years working with Wordpress, I always find the right way through the Google, but in this case I did not even know what to do, I really stacked :( So ... ...
1
vote
1answer
37 views

Trying to establish connection to External Database

I'm trying to get a connection to a separate external database from the database the wordpress site depends on. I have a PHP file inside the same location of my theme, it is basically a blank PHP it ...
1
vote
1answer
29 views

Help with a $wpdb MySQL Query

I'm wanting to expand on the following query to look at multiple meta_key and meta_value values that have been created with the Advanced Custom Fields (ACF) plugin. e.g. meta_key 'colours_%_colour' ...
3
votes
3answers
126 views

post__in for get_posts with a dynamic array

I am creating an RSS feed. I have created a table in my database with 400 post id's. I have the rss feed coded I am now trying to link the two so my RSS feed runs only for the list of 400 posts from ...
2
votes
1answer
1k views

How to filter a dd/mm/yyyy date from a custom field in a query

I'm trying to build a query in order to sort some posts by a date custom field, where the dates are formatted dd/mm/yyyy. It works by querying the database directly with get_results like in this ...
0
votes
0answers
28 views

Custom database tables for each forms

I'm wanting a forms functionality, where the form creator can allow the use to create custom tables. Like each form having a separate user specified table and user specified column name as per the ...
0
votes
1answer
42 views

$wpdb->delete column values IN ARRAY()?

I am wondering if this is possible? $wpdb->delete( 'table_name', array('id' => array(1, 2, 3)), array('%d') ); So, in this situation, it should remove 3 rows at once, and call the ...
0
votes
1answer
32 views

Print out Wordpress user ID - two sites with same code but different output

Trying my luck once more with more smarter and awesome peeps =D In my last question the issue was regarding getting wordpress user ID, which worked perfectly after someone steered me in the right ...
0
votes
0answers
11 views

How to search based on meta keys

I am trying to search custom post type based on meta keys but have no success so far I only have one post in this custom post type but no success. Here is the code. $args = [ 'post_type' => '...
1
vote
2answers
44 views

Need help writing a $wpdb query

I am trying to search through post meta for keyword matches but I'm new to MySQL and I don't know how to write my query. I can write a basic query for post_title matches but I don't know how to ...
0
votes
1answer
36 views

I can't write in my DB using $wpdb->insert

Building a plugin I'm trying to insert something in my DB but isn't works! My code is like that: global $wpdb; $table_name = $wpdb->prefix."mytable"; $wpdb->insert( $table_name, array(...
3
votes
1answer
604 views

$wpdb->prepare() warning in WordPress 3.5

I am receiving this warning when I try to run a database query: Warning: Missing argument 2 for wpdb::prepare() The offending query is: $result = $wpdb->get_var( $wpdb->prepare( ...
4
votes
0answers
59 views

$wpdb Query Result not coming but in phpmyadmin it works

Here is my query, when i run this in PHP file its returns NULL but same query in Phpmyadmin return row. Even I tried with $wpdb->get_row() and $wpdb->get_col() but the result is same for all. ...
0
votes
0answers
42 views

Search result by taxonomy name

Currently my search filters by title and I'm trying to filtered by taxonomy tags. How do you I do that. Here is my code: $query = " SELECT * FROM $wpdb->posts WHERE $wpdb->posts.post_status = '...
0
votes
3answers
34 views

Can't run database query

I am writing a function to query some information from a custom table in the database. It seems that I am unable to query the database on the field I need. function ch_details_from_id($id) { ...
1
vote
3answers
34 views

How to fetch an array in $wpdb?

I have a snippet that will select a data from database table. But I encounter an error: Warning: Invalid argument supplied for foreach() I encounter a new error: Notice: Trying to get property of non-...
0
votes
2answers
39 views

WPDB Placeholders and second argument for prepared statements

How can I set placeholder and second argument for that kind of sql prepare $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'attachment' AND ID IN ('".implode("',...
0
votes
2answers
21 views

$wpdb->last_error deosn't show the query on error

I am inserting data in the custom table using the $wpdb->insert. However, upon error I don't seem to get any information from $wpdb->last_error. What could be the cause of this? I already have ...
0
votes
0answers
28 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 $wpdb-&...
0
votes
1answer
12 views

Exclude category from DB query

I have next code: $drivers_all = $wpdb->get_results("SELECT DISTINCT meta_value FROM wp_postmeta WHERE meta_key = 'driver'") With this one I get the values of all fields “driver”. How can I ...
0
votes
1answer
18 views

How to use prepare to query with variables

Trying to write a prepare statement that works. This works: $countthem = $wpdb->get_var( "SELECT COUNT(*) FROM wp_cmapg WHERE lang = 'yes'" ); This does NOT work: $countthem = $wpdb->...
0
votes
0answers
24 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
1answer
35 views

wpdb get posts by taxonomy SQL

I need a list of posts of a specific post_type plus the name of a custom taxonomy term. This is what I got so far SELECT p.post_name,t.name as clientName FROM $wpdb->posts AS p, $wpdb->terms ...
2
votes
3answers
181 views

WP DB Error max_user_connections

I'm currently getting this error in the front-end only (not inside /wp-admin): Warning: mysqli_real_connect(): (HY000/1203): User xxx already has more than 'max_user_connections' active connections ...
1
vote
1answer
34 views

Undefined offset: 0

Here is my PHP function function getUserIDandPush($ul){ global $table_prefix; // Prefix for Database table global $user_login; global $wpdb; // Wordpress WPDB database method $dt = $...
4
votes
2answers
444 views

Differences between wpdb->get_results() and wpdb->query()

Who can explain me the differences between wpdb->get_results() and wpdb->query() in making generic queries to wordpress db?
0
votes
0answers
22 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 ...
-2
votes
1answer
25 views

wpdb related question

In WordPress documentation, it says: (https://codex.wordpress.org/Class_Reference/wpdb) SELECT a Variable The get_var function returns a single variable from the database. Though only one ...
0
votes
2answers
21 views

Mowing site to another domain in simplest way

I need to move my simple Wordpres site from www.mysite.oldplace.com to www.oldplace.com in most as possible simple and native way. My simple site specification: WP 4.4.2 Twenty Twelve 1.9 theme ...
0
votes
0answers
28 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 (isset($_POST['...
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 ...