Questions tagged [sql]

SQL (Structured Query Language) is a special-purpose programming language designed for managing data held in a relational database management system (RDBMS).

Filter by
Sorted by
Tagged with
0
votes
0answers
46 views

Any way to use FETCH_KEY_PAIR with $wpdb?

I'm trying to get key/value pair results from a query like PDO's FETCH_KEY_PAIR from a $wpdb query. The closest I found was the OBJECT_K output from get_results(). But that returns the key, but for ...
0
votes
0answers
11 views

Add a Custom Field and his value via SQL

I need a SQL query to add a custom field and his value to a wild number of posts (more than 5000 I think, this is an old news site). Some post that I manually updated for SEO already have that custom ...
0
votes
0answers
8 views

how to list all post that are in the custom taxonomy using $wpdb

global $wpdb; $custom_post_type = 'post'; // define your custom post type slug here // A sql query to return all post titles $results = $wpdb->get_results( $wpdb->prepare( "SELECT ID, ...
0
votes
0answers
4 views

Put a database alias on the args parameter from the Wordpress post_clauses filter

Well, I'm trying to geolocalize products on the search engine from the Woocomerce plugin. I manage to see that everything works from filters that can be added inside the method ...
0
votes
0answers
9 views

WooCommerce get specific orders by Customer ID SQL

Trying to get specific orders by the customer ID via a raw SQL query. I'd like to input which order IDs I'd like to retrieve, but only retrieve them if they match a specific customer ID, here's what I ...
0
votes
1answer
28 views

Display a number value from mysql query in WP

Anyone have a suggestion on how I can display the result of a SQL query in a WP post or page? The query statement is a SUM statement and I want to only display the resulting number value on the page. ...
0
votes
1answer
12 views

WP_query has incorrect wp_posts.post_name = 'asc' when I have custom post type called 'order'

This is my code : print_r($args) //Output array(6) { ["post_type"] => string(9) "order" ["date_query"] => array(2) { ["before&...
0
votes
0answers
6 views

all values not stock in array after request

I m working on a plugin. I get some values from db and put in array for create programmatically some pages. So, before the creation; he match the name in the array with the value of db if not exist, ...
0
votes
0answers
14 views

Good request for get id

Actually, i m trying to get id from the combinations of two table for display in differents pages. I have: wp_keyword id | keyword | id_secteur (join at wp_secteurs on id_secteurs) 1 agence web ...
0
votes
0answers
23 views

How to store sensitive user data (passwords)

I want to create a plugin addon that allows my sites users to share private login information in a secure manner. So they'll enter these private details in a form on the frontend and I want to be able ...
0
votes
1answer
38 views

CREATE TABLE with dbDelta does not create table

I based this code from the codex on the docs. I placed it in my main plugin file but it's not creating the database table. Have I missed something? // Database setup and hooks function ...
0
votes
1answer
16 views

How can I add a new row in a separate database when someone registers via Wordpress?

Apologies if this is question is too general or in the wrong location but I am new to SQL, Wordpress and web hosting. So I am a game developer using Unity C# to create a multiplayer game. I am using ...
0
votes
1answer
25 views

Looping the data from WordPress database using foreach

I am trying to fetch data from the WordPress database table using wpdb and loop it using foreach statement so as to output results in select tag. I created a custom WordPress template and this was to ...
0
votes
0answers
16 views

Job and Employee Performance Tracking with Product Safety

We are looking to connect a WordPress site to our database where an employee can scan an order barcode with an RFID scanner that was generated from our database and have the WordPress site query the ...
0
votes
1answer
34 views

get woocommerce product image url and price from database [closed]

I want to get some product data directly from the database, currently I have this, but I'm missing the featured image URL: SELECT p.ID, p.post_title, `post_content`, `post_excerpt`, t.name ...
0
votes
1answer
38 views

Clear Terms from Taxonomy for Specific Post IDs?

Trying figure out how I can use some SQL/$wpdb->query to delete all the terms from a taxonomy that are related to specific post IDs. The following works beautifully to delete all the terms from a ...
1
vote
0answers
15 views

Prevent duplicate records in plugin table

I'm working on a plugin that keeps track of like counts on every post in the site. When the plugin is activated a custom table is created to store all the data. The plugin then checks on every page ...
0
votes
0answers
13 views

sort title descending with title with number

please help me, i have title like this '1-nen A-gumi no Monster Chapter 2' '1-nen A-gumi no Monster Chapter 10' '1-nen A-gumi no Monster Chapter 2' '1-nen A-gumi no Monster Chapter 1' '1-nen A-gumi no ...
0
votes
1answer
29 views

Delete oldest wordpress post (SQL query)

I've reached the database limit on my hosting platform. I want to add a function to my functions.php that deletes the oldest post in my database anytime that I publish a new post. function ...
0
votes
0answers
14 views

How to optimize query which remove duplicates for 2 million items

Good evening, This is my query which should remove duplicates from table. How can I optimize this for two milion records? DELETE p1 FROM wp_ads_platform_users p1 INNER JOIN wp_ads_platform_users p2 ...
-1
votes
1answer
29 views

How to write inner join using posts_clauses?

Can someone please show me how I can achieve the same result with this SQL: SELECT * FROM wp_2_posts INNER JOIN wp_2_icl_translations ON wp_2_icl_translations.element_id = wp_2_posts.id AND ...
0
votes
1answer
36 views

How To Write An Inner Join With WP Query

I have a ACF relationship field for a custom post type, properties. Moreover, the content of these properties can either be in English or Spanish. When I use a ACF relationship field to associate ...
0
votes
1answer
40 views

show badge with count for pending items in custom post type

This code I have is working but I am not sure if it is the right way to do this. Basically when a user adds a record to a custom post type it goes straight to pending and needs an admin to publish it. ...
0
votes
0answers
15 views

SQL Query - custom tax_query not working when querying two taxonomies

I have a created a custom table in my WP database called wp_opportunities which stores locations with their lat and long. I'm trying to query the table based on the taxonomy term set on the post ID ...
0
votes
0answers
8 views

Excluded category from SQL query but not excluding posts from that category

I am creating a custom search for my site and written following query. I am getting problem with the query. I have excluded some category IDs like 144, 303, 333. It is excluding these categories but ...
0
votes
0answers
12 views

How to display both first_name and last_name meta values in Wordpress Using SQL

Am trying to loop bids on different posts by a specific loggedin user with uid=2 to display first name and last name of the owner of the post. However the loop or rather var_dump only returns 1 result ...
0
votes
0answers
9 views

Set products variations images as parant main image

The scenario is: a site with lots of variable products. None of the variations has a featured image. We need them to get their parent image - not jus in the front-end, also in the backend (as if I ...
0
votes
0answers
7 views

Wordpress Website Shows Download Box on New Server

What I did: I took backup of my Wordpress website with SQL DB and upload it to another domain but instead of homepage, it shows a download box to save it as "download". I tried disabling all plugins ...
0
votes
0answers
12 views

WordPress: SQL query to set TAG or CATEGORY if 1 or more words are written in post_title

SQL I need to set the TAG or CATEGORY in a post if there is a keyword in the post_title. Eg: IF "abc" word in post_title THEN set post TAG to "zzz" or IF "abc" word in post_title THEN set post ...
0
votes
0answers
27 views

Update post_meta table from other database

I need to take values from an old database to a new one. Specifically a plugin's meta value of WooCommerce products. I've got the same products data in both tables but the IDs are not coincident, so ...
1
vote
1answer
25 views

How do I see the mysql query generated by get_posts( $args )?

I'm trying to use get_posts( $args ) to get some custom post types. Is there a way to see the mysql query generated by the get_posts function?
1
vote
0answers
14 views

Querying wpdb using PHP

I'm a beginner trying to query a table in my wordpress database and would appreciate some pointers on where I'm going wrong... I've got a table of cricket statistics, and want to get the highest score ...
0
votes
1answer
65 views

SQL: How to find all attachments that are not used in any posts/pages/custom_post_types

I have a wordpress installation where the posts also contain attachments that were not embedded in the content by using the media library -> add. I would like to find all attachments that are not ...
0
votes
1answer
80 views

What is the equivalent WP_Query of a SQL Query?

The problem There is a post_author post type, the main post relates to post_author: every post has one post_author. I need to have a list of all post authors to be sorted in a descending order by ...
0
votes
0answers
30 views

Fix Potential Security Issue in Custom Taxonomy Search Functionality

I want to add some functionality to a client WordPress site that allows you to include taxonomy terms from custom post types in the Wordpress search, and come across the following answer: Include ...
1
vote
0answers
10 views

SQL mass removal query for pending subscription [closed]

I have in a woocommerce shop 69 000 "pending cancelation" subscription. Is there anyway to make a mass removal of those by SQL ? Here is the URL settings to display them : post_status=pending&...
0
votes
1answer
14 views

Find locations of all featured images of draft posts via SQL

I'm trying to get the file locations of all featured images used in draft type posts via SQL and phpmyadmin. posts type attachment should hold the location of the image in the guid column. SELECT ...
0
votes
1answer
110 views

Woocommerce - get daily sales meta

I am writing custom woocommerce plugin. Does woocommerce has any daily sales report of each product? I know, that get_post_meta can show total sales of certain product, but I need to show sales of ...
0
votes
0answers
25 views

Insert and retreive data from custom database from Wordpress page

This is the first question I'm asking here, so I'm open to any feedback on how to clarify my problem/question! I have created a small javascript game on a wordpress page with "custom html". I'd like ...
0
votes
0answers
12 views

How can I automatically make a post for every entry in my database?

I am very new to WordPress development so I apologize for any clear lack of understanding present in my question. I am hoping to make a review website for podcast episodes. I have used Python to web ...
0
votes
0answers
27 views

Limit total number of post and post per page with get_results

I'm using a custom table with a additional column, so I can't use regular wp_query. My code is working great except for the total number of post. I want to display 5 results per page (which works ...
0
votes
0answers
42 views

Specific SQL Query to filter certain WooCommerce products

I've written a script that generates a .PDF based on products in the WooCommerce store, the idea behind this is that a client can print it, fill it in and fax it to the company. This works all fine, ...
0
votes
0answers
8 views

SQL: trying to update posts that have certain custom meta

struggling with an SQL command.. I want to change a post type from 'post' to '2month' that have custom meta (low_jobs = 'under 100') and do not have certain categories UPDATE wp_posts.ID SET ...
0
votes
0answers
34 views

WordPress creating excessive joins on meta_query with search

I've a pre_get_posts filter with a check for main query and search, in this check I add a meta query: $meta_query = array( 'relation' => 'OR', array( 'key' => 'exclude', 'value' =&...
0
votes
0answers
35 views

SQL database import #1046 error

As I am reuploading a WP website backup on a new host and importing the SQL database from phpMyAdmin, how do I solve this #1046 error ? Error SQL Request: — — Table structure for table ...
1
vote
0answers
187 views

How to get all products from an order including variations via SQL query?

I have searched a lot and hope someone has an answer. I want to run a query in the Wordpress/Woocommerce database and fetch from an individual order, all details, including the variations of a ...
0
votes
0answers
72 views

WP_Query adds “(wp_posts.ID = '0')” so no results are returned

I am doing a very simple WP_Query: $query = new WP_Query([ 'pagename' => 'some-post-slug', 'suppress_filters' => true // used by WPML to search in ANY language ]); However, the ...
0
votes
0answers
14 views

SQL query hanging php

I'm having issues with a fairly large WordPress site creating 45+ php-fpm pools. My hosting company says it is some long running SQL queries causing the problem and gave me this: +-----+-------------...
0
votes
1answer
63 views

I want to run Sql Query in script how can i do this

Thats What I tried But it give console error. i didnt understand how can run this i Have pass jquery variable to sql query but it isnt working <script type="text/javascript"> ...
0
votes
0answers
561 views

Update WooCommerce stock status with SQL query if stock value is greater than 0

I'm attempting to update a large product catalogue using a SQL query via phpMyAdmin if: the _stock_status = onbackorder the _stock > 0 Queries attempted: Update wp_postmeta Set meta_value = '...

1
2 3 4 5
15