Questions tagged [wpdb]

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

Filter by
Sorted by
Tagged with
0
votes
1answer
12 views

Why $wpdb->insert and $wpdb->update not working server but it is working in localhost?

I am working in a wordpress site, I started to work in local enviroment using xampp server. I used wpdb to do operations with the database like this: global $wpdb; $name = $wpdb->get_results(...
0
votes
1answer
28 views

How to get row value from wpdb

I want to echo 'yes' if the "notification" row value is 1 I tried to do with this code: global $wpdb; $row =$wpdb->get_results("SELECT * FROM wp_users"); if($row['notification'] == 1){ ...
2
votes
2answers
109 views

$wpdb->query() vs. $wpdb->get_results() vs. phpMyAdmin

I have this code: $query = "SELECT * FROM $wpdb->posts INNER JOIN $wpdb->postmeta ON $wpdb->posts.ID = $wpdb->postmeta.post_id ...
0
votes
1answer
37 views

Displaying SQL query result from user input via wpdb

I'm a bit stuck with one of my task which is to require a user input for an 'ID no' and it shall go through a table in my WP and display the result on the same page (after hitting Submit). I'm ...
0
votes
0answers
11 views

WP SQL sintax to filter by multiple criteria

Ciao guys, I am trying to get products by an $wpdb->get_col() SQL query, but I am in trouble with the SQL syntax. I need products which have an exact category and IN at least one taxonomy terms. ...
0
votes
0answers
18 views

Inserts of Custom Fields to postmeta are not persisting

I have a script which, after creating a post, inserts a number of rows into wp_postmeta for the just-created post. The rows are inserted, and opening the post for editing shows these values where I ...
0
votes
2answers
51 views

Connecting to external oracle database

So I'm trying to connect to an external db in order to access/update information located on a different non-wordpress database (oracle). I tried constructing a new wpdb object (as suggested by many ...
-1
votes
1answer
16 views

query using wpdb in wordpress gets me no result

I get no result unless i cut the string title to "Gocomma 10W QI Wireless Fast Charger Car Mount Holder " ... $title1="Gocomma 10W QI Wireless Fast Charger Car Mount Holder - 2pcs (it)"; $...
-1
votes
1answer
21 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
18 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
16 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
2answers
20 views

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

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
24 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
20 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
83 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
26 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
21 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
38 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
54 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
25 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
85 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
104 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
18 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
39 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
28 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
26 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
25 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
184 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
60 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
60 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
71 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
36 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
81 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
27 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
51 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
27 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
48 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
111 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
30 views

Sort custom post type by other custom post type field. (Places by their reviews average rating)

I'm trying to sort Places (first custom post) by its Reviews (second custom post) average rating. So, basically I have two custom post types, one is Places and the other one is Reviews. Reviews have ...
0
votes
1answer
52 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
34 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
33 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
30 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; $...