Questions tagged [wpdb]

The wpdb class, accessed via the $wpdb global variable, is used to interact with the WordPress database

0
votes
1answer
16 views

$wpdb->get_var returns 0

I use following code to get a number : $where = 'WHERE type = 4 AND active = 1 AND user_id = ' . $user_id ; $user_followed = $wpdb->get_var("SELECT COUNT( * ) AS total FROM {$wpdb->tablex} {$...
0
votes
1answer
16 views

Get table parameter and save in meta value

I want to get number_1 and number_2 and save in meta_value in table wp_postmeta. How do I do the same? The id_help_i and the same of the $post-> ID. Some id of the table wp_table_help_i does not ...
0
votes
0answers
14 views

SQL query that returns a list of duplicate posts IDs, comparing their post_parent and a post meta value?

I want to build a SQL query that would fetch all the duplicate posts; by comparing their post_parent and the 'link_url' post meta. ID | post_parent | link_url meta 1 11 ...
0
votes
1answer
12 views

Can I use a wpdb object to connect to a non-Wordpress Oracle database

I simply have a quick question. I've found information related to this, but I'm not completely sure if this is possible. I know that I can create a second database connection using the wpdb object as ...
1
vote
0answers
23 views

Return terms from multiple taxonomies using $wpdb

I would be the first to admit that I know next to nothing about SQL queries, but after numerous searches and some trial and error I was able to cobble together a query that returned the results I was ...
0
votes
1answer
16 views

How do I create a WP endpoint that retrieves all custom post types that have a tag?

I have a custom post type, let's call it 'capability'. Each capability can have one or more tags. I have a searchbox on the frontend that the user can type into to search for all capabilities that ...
0
votes
1answer
18 views

$wpdb->insert inserting only f character in custom table

I have made a quick $wpdb->insert function that adds content with an AJAX function. The goal is to insert the form data into a table. Here is my Javascript function calling the ajax: $("....
0
votes
0answers
28 views

Modify post image in full size

I have a website where the client attached many “full size” images to posts, most of them in 5000px width, is it possible to run something for resizing those images to large? Instead of going through ...
1
vote
3answers
51 views

$wpdb -> Batch insert from XML File?

Actually im stuck on this! XML-File ~ 140.000 Rows Filesize ~ 9.0 MB LOAD XML INFILE 'file_name' isnt't allowed ( shared hosting! ) The supplier provides a single XML file with quantity and sku. The ...
0
votes
1answer
23 views

Top tags with minimum number of posts

I'm getting the most used tags in the 1 day interval and everything works fine but how do I add the limitation to get tags with at least 5 posts and order them by counting? Actual code: $term_ids = $...
0
votes
0answers
24 views

Database Query not accepting my WHERE LIKE wildcard in my PHP code?

I have a query that works fine when I run it in PHPMyAdmin, but does not return anything when ran via the website form post. I copy and paste the exact SELECT below, replace both$searchByText and $...
0
votes
0answers
18 views

Display Form in Admin Panel and Save data to Database

I have a Add New Button in Admin Panel like below image. I would like to display a Form like below image and save data to a Database after clicking the Add New Button. How can I do that ? I am ...
0
votes
0answers
23 views

I want to update my postcontent with $wpdb

When I post a post to my site though webapi,there already had a same post_title in my post list, So I just want to update my post_content or replace all data to the old post but not let wp create a ...
0
votes
1answer
35 views

PHP Warning: Error while sending QUERY packet

I have woocommerce website which give database error from 4-5 days. I checked the error log, the error is: PHP Warning: Error while sending QUERY packet. PID=31071 in /home/goldenwiggles/...
0
votes
0answers
23 views

wpdb prepare placeholders for MySQL keywords

I have a function that takes inputs that will be used for keywords in the query. I want to use placeholders for these things in the query string, as otherwise there will be a sqli vulnerability. Here'...
1
vote
1answer
56 views

Get stock by custom meta field on all Woocommerce variable products

In WooCommerce, I have a custom meta field "Brand" on my products, and each product is assigned with one of the Brands. Now I want to get total stock for each brand from all products and I have only ...
0
votes
1answer
53 views

How to prepare an array of values with $wpdb

I am looping through an array of products and want to create an OR string with the product skus. From my understanding, you pass a query and the variables to replace the placeholders in the SQL. So ...
1
vote
1answer
17 views

Network Plugin Creating Pages for Different Subdomains

I have a network multisite setup with subdomains. It looks like this example.com <--- (this is the main site) sub1.example.com <--- (subdomain 1 of the main site) sub2.example.com &...
0
votes
0answers
36 views

Images names not inserting in Wordpress Database from Dynamic Add / Remove fields

I have created dynamic add / remove fields in which one is file upload fields. Everything is working fine. But there is one problem. When I add images in file fields and fill other details in other ...
0
votes
1answer
31 views

I can't update my data through $wpdb

I am trying to update my sql data through $wpdb, but can't... If anyone can help what's the real issue? $updated_version = $wpdb->update('wp_visitors', array('views' => $updated), array( '%d' ))...
0
votes
1answer
18 views

Trouble running $wpdb->query() with last_insert_id

I am trying to get a primary key from a coupon table to put it in my target table as a foreign key. In between I would like to run a query to get the last insert id. I can't get the syntax right ...
0
votes
0answers
35 views

Doesn’t call user information to include “wp-load.php” in an external php file

Doesn't call user information to include "wp-load.php" in an external php file. <?php require_once( dirname( dirname( __ FILE __ ) ) . '/wp-load.php' ); global $wpdb, $user_ID; echo $user_ID; // ...
0
votes
0answers
26 views

stop execution and Display Errors when inserting data to custom table

I created a stats table. on a daily basis I retrieve data from Post meta, aggregate it and insert it into the stats table (code bellow). function updatePostDay($postID, $month) { global $...
0
votes
1answer
24 views

Issue running db create table query from static method

I suspect the way I call the table creation function below is the culprit for no table creation (nothing shows in the debug log or query array). Can anyone see my mistake? // main plugin file, ...
0
votes
0answers
13 views

how to make Wordpress DB lookup code to do “if” funcation

I have a wordpress website that using WPUM to creat accounts and mange them and a coustem plugin for memberships. When users creat an account they chose from membership plugin membership kind ( Sun - ...
0
votes
1answer
21 views

How to get INSERT errors from $wpdb?

I have these $wpdb->suppress_errors(false); $wpdb->show_errors (true); $wpdbp = $wpdb->prepare($preparedQuery->query, $preparedQuery->values); $result = $wpdb->...
2
votes
2answers
164 views

Is there a (better) way to access $wpdb results?

I have this: global $wpdb; $wpdbp = $wpdb->prepare('SELECT EXISTS ([some query] WHERE user_id =%d);',$target_user_id); $result = $wpdb->get_results($wpdbp); I want to know if the ...
0
votes
1answer
45 views

How to get a list of WordPress default database tables?

Is there any solution to get a list of default database tables in WordPress? I have used $wpdb->tables() but even with blog argument, it returns a list that includes other tables too. (I have some ...
1
vote
1answer
50 views

Get .subsubsub count of post per status queried using pre_get_posts

My following query using pre_get_posts shows the Author only certain posts or pages with certain statuses that s/he should only see and of what belongs to him/her. Is there any way I can get a count ...
0
votes
0answers
51 views

Warning wp-db.php on line 1172

From time to time my site has presented these warnings in the log: Warning: mysqli_real_escape_string() expects parameter 2 to be string, array given in /.. mypath ... /wp-includes/wp-db.php on ...
1
vote
1answer
30 views

Global $wpdb is not showing correct data with function call

I have a code which shows last 3 recent updated pages or post. This code is working perfectly when I add it on theme sidebar.php file. <?php $today = current_time('mysql', 1); $count = 3; if (...
0
votes
1answer
43 views

Search database with WPDB using a php variable

I'm trying to do a basic search feature for my website database. I want to search the text content inside a custom database table using Wordpress and WPDB. For some reason the search is not returning ...
0
votes
0answers
20 views

WPDB Get Array Of Taxonomies With Post Count

I'm trying to get an array of taxonomies with the count of post types using $wbdb. I would like my array to be: [ [term_name] => [post_count_by_term] ] I've started setting up my SQL query, ...
0
votes
0answers
45 views

SELECT max(meta_value) FROM wp_postmeta in current Category

I need to display the maximum price and minimum price of product From the current category I found this topic SELECT max(meta_value) FROM wp_postmeta WHERE meta_key='price'... stops working ...
0
votes
0answers
26 views

How to have differents sites share the same tables of DB?

I want to have multiple versions of my site that share the same database. I'm wondering if this is as simple as just cloning the site and then in the wp-config having them all use the same database? ...
3
votes
1answer
43 views

Get data from database table by post_id to get data from second database table

I have two db tables: wp_comments and wp_ratings. I'm trying to create a query using $wpdb which has to do the following: from wp_comments I have to get the comment_ID's where the comment_post_ID is ...
0
votes
3answers
78 views

Sql query triggered twice

I am trying to collect data from a search box. Conditions; if the value exists, update the counter field based on how many times it's been searched. Problem: when a duplicate value searched in the ...
0
votes
0answers
20 views

Sort custom post type by other custom post type field. (Places by their reviews mean vote)

I'm trying to sort Places (first custom post) by its Reviews (second custom post) average (mean) vote. So, basically I have two custom post types, one is Places and the other one is Reviews. Reviews ...
0
votes
1answer
35 views

Order by custom table and multiplication

I want to order posts by multiplying values from a custom table. +---------+------+------+------+------+------+ | post_id | a | b | c | d | e | +---------+------+------+------+------+--...
0
votes
2answers
29 views

How to work with constraints on wordpress user metadata?

For example, I want to add a custom user metadata field for projects he is assigned to. But this field must have a foreign key constraint to another table to make sure that the project it is ...
0
votes
1answer
31 views

Connecting to a different database

In my site I'd like to pull in data from another table, without having to create an API from the other site. I have seen that you can do something like this: $wpdbtest_otherdb = new wpdb('...
0
votes
1answer
25 views

Getting Error Trying to Create Table

I'm trying to create a new table in phpmyadmin. I'm using MAMP and this is of course inside wordpress. <?php function testtheme_database() { global $wpdb; global $testtheme_db_version; $...
0
votes
2answers
31 views

Where is the HTML-handler part in the wpdb class?

I'm trying to understand how datas are being handled when saving to the database in the wpdb class. I have searched for where HTML string datas are handled and found a method in the $this->query() ...
0
votes
1answer
72 views

wpdb Cannot Update column in Database

In the custom table, I try to update a specific column with using $wpdb->update class and using HTML form for updating one column that has same id (in here dlname Is ID of data ). The problem is this ...
0
votes
1answer
18 views

Display category names on edit user profile using $wpdb

On the 'Edit Profile' page I'm trying to loop through all the category names using $wpdb. Here is my code <?php function custom_user_profile_fields($profileuser) { ?> <h1>Select a ...
1
vote
1answer
34 views

Using $wpdb->update but confused on the WHERE in and SET

I'm confused on using the where in the $wpdb->update :/ These last few lines of my code are MEANT to update a table with an IP address when software is activated. If they change IPs it records the ...
0
votes
1answer
28 views

Using $wpdb | checking entered email against existing emails in db

Without ranting too much, here is my snippet: if (empty($_POST["email"])) { $emailErr = "Email is required"; } else { $email = test_input($_POST["email"]); // check if e-mail address is ...
1
vote
1answer
96 views

Foreach loop using $wpdb not results from rows

I'm using $wpdb to develop a plugin to check for some row fields to see if they match and echo true or false. My original code was working when it was a separate mysql DB and accessed that way. As its ...
0
votes
0answers
29 views

No result after wpdb->insert

I have implemented my own plugin (PHP file). It contains a form with questions with input type = radio. I want to submit the answers and load them into the database. My action is calling another PHP ...
-1
votes
1answer
23 views

How much does $wpdb->prepare(), then $wpdb->query() VS straight $wpdb->query(), can slow down the load time of whole page

Let's assume that the $wpdb->query() is properly escaped as needed, so there is no must for use of $wpdb->prepare(). However, some new requirements at Envato, not the w.org, requires to go over ...