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
28 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
26 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
12 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
13 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
14 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
56 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
19 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
19 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
22 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
14 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
35 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
17 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
22 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
13 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
33 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
14 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
55 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
38 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
13 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
15 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
41 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
69 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
149 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
194 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
27 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
25 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
13 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
28 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
54 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
57 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 ...
0
votes
1answer
13 views

How to set up prepared query using IN statement

I am a tad bit confused on how I would set up a SQL IN statement using a prepared query. Here is the code: $in = implode(',', array_fill(0, count($product_ids), '%d')); $results = ...
0
votes
2answers
162 views

How to query the WordPress database to get posts of a certain custom post type, taxonomy and field?

I have a custom post type named store and I have a custom taxonomy city, I also have a meta box with a field that is stored with update_post_meta( $post_id, 'store_postal_code', $postal_code ); it ...
0
votes
1answer
103 views

wpdb and acf via wp rest api

I made a custom endpoint with wp rest api for /wp-json/dn/locations which in turn runs the following wpdb query $sql = "SELECT * FROM wp_posts p WHERE p.post_type = 'location' AND p.ID = 133;"; ...
0
votes
0answers
42 views

Inserting and updating rows with wpdb indreases integer fields by 1 point sometimes

OK, here is the situation: I have a table with the fields "ID" (int, auto incremented), "query" (text), and "counter" (int). I am trying to make it so if a selected value exists in the "query" column, ...
1
vote
1answer
34 views

Problem in inserting row to custom database table

I have a custom table in database named wp_tasks which has 5 fields. But I am unable to insert the current time to assign_date field. wp_tasks table id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, ...
0
votes
1answer
127 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 ... ...
0
votes
0answers
75 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 ...
0
votes
0answers
60 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
66 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
47 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
112 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
38 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
30 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
106 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
24 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
22 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
83 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
55 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
97 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 ...