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

New User ID not working in custom function with user_register hook

I'm adding data to a table whenever a new user registers on the site. add_action( 'user_register', 'auto_follow_admin', 10, 1 ); function auto_follow_admin() { global $wpdb; ...
0
votes
0answers
16 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 ...
1
vote
1answer
27 views

How would I format a query that depends on post parent taxonomy

I'm trying to do a custom query which is outside the scope of a single WP_Query, I think I should be using $wpdb but my SQL is a bit ropey. Also I only need the post IDs returned not post objects. ...
0
votes
0answers
6 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
20 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 ...
0
votes
1answer
25 views

Run an update query in a function

I need to run the below in a function, it updates my database if certain conditions are met. I can't get it to work and I can only assume its because of the "SET @newnum" at the beginning. I've ...
0
votes
1answer
12 views

MySQL Select within WP Page template

I have one WP page which contains a form that posts data to a table in the Wordpress database called "members", data such as first name, surname, email, role and bio. Table posts fine and data is ...
0
votes
1answer
16 views

$wpdb->get_results breaking page?

I'm trying to generate a list of years that have posts on a Wordpress page using a "php in posts" plugin that has a shortcode. but the code I'm using seems to break the page. What could be the issue ...
0
votes
1answer
30 views

Multiple wp_options tables to share content across installs

My application has >10 user_roles, each able to perform completely different tasks, provided with an custom backend and no access to wp-admin. The extra functionality each user_role gets to use is ...
0
votes
0answers
17 views

Does WP query update accept variables being built into it?

Trying to figure out if this is a WP specific quirk. The var_dump code shows the correct string to be inserted but the last query dump at the end shows an incomplete query with no variable being ...
0
votes
1answer
32 views

Custom select query two tables by a meta key

I'm using an event plugin which creates wp_ftcalendar_events table in database with start_datetime column. Here's image of whole table: I want to query my posts by start_datetime. I know that I ...
0
votes
0answers
4 views

$wpdb->get_var not matching after first loop through foreach

I'm trying to match my array with a entries in a table and retrieving the ID of the entry. So I have the following array called $features. Array ( [0] => Body Side Moldings: ...
1
vote
2answers
47 views

Getting users who registered 360 days from current date

As per the title, what I want to do is run a custom query that (using WP-Cron) will run once a day to check for users who registered exactly 360 days before the current date (don't need time, just ...
0
votes
1answer
40 views

How to insert a single row to WP database table?

Intro: I have a function that handles a contact form variables in my website. user enters name, email and text. function.php gets variables using javascript. I get more information on the user ...
4
votes
1answer
126 views

So much data in postmeta

Last year started using custom fields and in one year I have 230,540 rows in wp_postmeta table. This year will add more data and new fields and I don't know what to do, to create new table or continue ...
0
votes
1answer
28 views

How to fix this insert? Don't work for me!

I need to fix errors of this insert because this don't work in my script. I'm a beginner in WordPress SQL. Thanks $wpdb->insert('wp_cadastrados', array ( 'ID' => NULL, ...
0
votes
1answer
35 views

Why is this $wpdb query looping 5 times?

I want to only return one value for this query, it's in my functions.php file. The idea is to return a value that I need once post_meta has been updated. It's returning the same (correct) value 5 ...
0
votes
0answers
23 views

$wpdb how can i save my postmeta table before querying it

This function is in my functions.php file. The query returns the value I'm looking for via phpmyadmin, but only AFTER the function has been run in WordPress. add_action( 'transition_post_status', ...
0
votes
1answer
42 views

wpdb query not returning results containing single quotes

I'm using a simple $wpdb query that searches the database for all other posts with the same title as the current one and then displays a link to them on the current post. So if I go to a post titled ...
0
votes
1answer
34 views

Problem in using wpdb

I used "wpdb" in my code But it was not working and the following error: Fatal error: Call to a member function insert() on a non-object Notice: Trying to get property of non-object" in ...
1
vote
1answer
41 views

Convert simple SQL Query to WordPress query

I'm trying to 'batch' update the value in my post_parent fields in my wp_posts table. I can do it from within phpmyadmin using the following SQL Query: UPDATE wp_posts SET post_parent = '8' WHERE ...
0
votes
0answers
17 views

How do I update post based on meta_key in another table?

So I have a function that is called by the wp_schedule_event (cron job) once daily. The goal of the function is to set all posts with a field wpcf-engine-days-to-go that has a value of "0" to a draft. ...
0
votes
1answer
19 views

wpdb insert working in one function, but not another

I have the following function: function addToShortlist($propref) { global $wpdb; if (isset($_SESSION['shortlist'])) { $shortlist = new Namespace\Shortlist($_SESSION['shortlist']); ...
1
vote
1answer
15 views

When and why should I use $wpdb different return types?

This one returns an object $mylink = $wpdb->get_row("SELECT * FROM $wpdb->links WHERE link_id = 10"); An associative array $mylink = $wpdb->get_row("SELECT * FROM $wpdb->links WHERE ...
0
votes
1answer
75 views

Convert a WP Query into a simpler SQL query to fetch only COUNT of posts

I have this WP Query running for each row in my admin screen for a certain post type: $entry_args = array( 'meta_key' => 'wp_comp_entry_competition-id', ...
0
votes
0answers
46 views

Export Wordpress Table to CSV from page

I want to export my members table to csv format on my default download location. So I used a shortcode in functions.php and called it on a page. I am getting an already sent header warning and csv ...
0
votes
1answer
28 views

Site going down due to slow queries

My site keeps going down and the host says it's due to some slow queries overloading the server. They've supplied a list of slow queries, any pointers as to what I should be doing to get rid of or ...
0
votes
1answer
17 views

meta_value timestamp older than now

In my wp_posts table I want to select the rows where post_type == event. I also want to a connection with wp_postmeta from the specific row. In my wp_postmeta table I want to do a where like this: ...
0
votes
1answer
43 views

form $_post action value gets truncated after it passes through two forms

There are three pages page1, page2 and page3. When I press submit on my first form on page 1 my group name field can be catched with $_POST['groupname'] in the destination page but in the page 2 I ...
0
votes
0answers
24 views

Passed variable gets undefined variable error on insert on next page

I am passing a variable with $_POST to another page and on the destination page I want to perform an insert operation and want to use that passed value . The variable "$mygroup" is coming from a forms ...
1
vote
2answers
40 views

Database query works fine outside Wordpress

This is my code <?php global $wpdb; $rows = $wpdb->get_results("SELECT `submit_time` AS 'Submitted', max( if( `field_name` = 'Salutation', `field_value` , NULL ) ) AS 'Salutation', max( if( ...
0
votes
0answers
20 views

Get wp_dropdown_users to set variable in page

I have a page my-bookings.php which is generated by Events Manager Pro Plugin. Is shows all bookings made for the logged in user. Great overview, but the same overview is not available for Admins and ...
0
votes
0answers
28 views

I am not getting result from php function that is json encoded

So I am trying to build an array of post data. But when I json encoded it I am not getting back the post object data from the database. Here are my two functions public function ...
0
votes
0answers
17 views

wpdb insert escaping

I have created a function that adds some data to a database table using wpdb->insert() Each time the form is submit it adds back slashes to single quote ' character, if form validation fails and ...
0
votes
0answers
38 views

Loading posts from another wordpress database on the same server

I've searched quite a while and found several solution but apparently I'm doing a lot of stuff wrong. I'm having 4 different Wordpress sites and need to load the latest 2 posts of each site. For ...
0
votes
0answers
15 views

Object Cache - Avoid db queries totally

I am using object cache and have cached just about all queries but am stuck with the last 3, on a post archive page. They are all wp core queries. SELECT SQL_CALC_FOUND_ROWS wpm_posts.ID FROM ...
0
votes
1answer
100 views

Updating with $qpdb->query() always returns 0 rows affected

I'm experiencing an odd situation while running an UPDATE with $wpdb->query(). Given the users table, with columns user_id (Primary Key) and status, and the user 3 existing and with status 0, I ...
0
votes
1answer
50 views

duplicate entries in database while using save_post or wp_insert_post

Here is what I am trying to do - I have created a custom table in the database and I am trying to enter data into it everytime a post is created. The database-entry needs to happen ONCE AND ONLY WHEN ...
0
votes
1answer
17 views

Quotes in table name

Since WP3.5, prepare() accepts placeholders as a security measure, instead of just appending the argument to the query. Therefore, $wpdb->prefix needs to become a second parameter, called by %s: ...
0
votes
1answer
24 views

$wpdb returns duplicate posts

I have created a shortcode which shows the posts which were created after the user last logged in. The shortcode is working perfectly fine, but I am not sure why but I am getting 7 duplicate posts. So ...
0
votes
2answers
54 views

Saving custom term value to the database in new table

So I'm trying to save the value of a custom term to my database. The table is created as is the custom term. The code below outputs the text field onto my custom terms page but it just doesn't save ...
0
votes
1answer
85 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 ...
1
vote
0answers
201 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 ...
7
votes
2answers
228 views

Is it mandatory to use $wpdb->prefix in custom tables

Sorry if this question is trivial. I'm just beginning to develop plugins in WordPress. In all the tutorials I found this: while creating the custom tables, $wpdb->prefix is used. Example: ...
0
votes
0answers
31 views

wpdb giving different results then query in SQL Editor

I'm trying to read candidates and the relation with expertises from 2 custom tables in my WP Database. This is my WPDB query : $candidates = $wpdb->get_results(" SELECT * FROM ...
0
votes
0answers
34 views

Run insert if no entry otherwise run update with ajax

Below function works with ajax ... but I am getting a null result ... I want that if there is no data in the database then insert operation is performed and when there is data the update should work. ...
1
vote
1answer
16 views

How can I migrate mysql_fetch_array to $wbpdb?

I am migrating a script with direct MySQL access to the $wpdb class, but it fails. Below is both original and new code next to each other. What is wrong? <!-- ...
0
votes
1answer
31 views

Why my query does not run with prepare

Hi Below is my query and it works with prepare keyword on the localhost but whenever I use prepare keyword with my queries on live server the data does not show up and as soon I remove prepare from ...
0
votes
1answer
70 views

$wpdb->prepare is not working like mysql_real_escape_string

I'm working on a WordPress plugin and recently I have planned to migrate from SQL to $wpdb. I'm using a method called $wpdb->prepare instead of mysql_real_escape_string but it does not work. Here ...
0
votes
0answers
79 views

$wpdb->get_results returns NULL

$qry = 'select * from wp_wcmanage_9999 where order_updated IS NULL'; $get_orders_data = $wpdb->get_results($qry, ARRAY_A); var_dump($get_orders_data);// Returns NULL When i am executing same ...