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
1 answer
23 views

Has the table name in SQL for Wordpress changed from WP_posts to WPCS_post?

I ran this query in SQL in PhyMyAdmin UPDATE wp_posts SET post_content = REPLACE (post_content,'https://www.example.com/wp-content/uploads/','https://www.cdn.example.com/'); Though it ran, then gave ...
0 votes
0 answers
16 views

How to sort search result by post_title, then by post_content

How to sort search result by post_title, then by post_content For example - if i search for word "Ball" i want to get results where "ball" exists in title, then the results where &...
0 votes
1 answer
7 views

This SQL request call all time and overload my server : SELECT meta_value FROM wp_sitemeta WHERE meta_key = 'wp_installer_network' AND site_id = 1

I have this SQL request who is call every time on my website and take between 1 and 2 secondes to execute so my serveur break down. What is it and how delete it ? SELECT meta_value FROM wp_sitemeta ...
0 votes
0 answers
49 views

Possible SQL injection. How to locate and fix?

Google Search Console is saying that certain suspicious URLs in my site are returning a 403 error. They look exactly like this (the links below are not my sites, just examples): https://www....
0 votes
0 answers
55 views

Deleting the MySQL database

My SQL file has been deleted and I don't have a backup of it, if my WP file exists, how can I create a database for it? Thank you in advance for your help
0 votes
0 answers
12 views

Batch Scanning and Deleting Empty WordPress Posts

I found a solution, How To Delete Post's With Empty Content Using WP-CLI. I am Looking For a SQL Query Version That Will Delete All Post's Eith Empty Content. Here Is the WP-CLI Version- wp post ...
0 votes
0 answers
37 views

Retrieve data from external database and insert back in

I have some code in my functions.php which inserts from fields into an external database table. and that part works okay. I then want to get the ID of the row I have inserted so I can insert into ...
0 votes
1 answer
16 views

Group By query based on Custom Field

Hello I have a field name team and I would like to get the total amount that each team has been gatthered Im trying to echo the team name and total amount and group it by team but it doesn't work. ...
  • 13
0 votes
0 answers
18 views

Use a woocommerce hook to create a table and populate it with a query

In my Wordpress database I created some custom tables. I want to query these tables and display it on a woocommerce item page. Using the code snippet plugin I added a custom html table to the item ...
0 votes
0 answers
16 views

How to change and edit users according to the extension in the URL

I built a nice system that simulates a "battle" when a certain button is pressed, it updates the users' data accordingly, at the moment it works on one step and it is built in a plugin, I ...
0 votes
1 answer
27 views

Get count of rows based if column exists in two different tables [closed]

I have two custom tables which both contain a column called reference. wp_invites id lead_name reference 1 John fRgOeRkFeHIm 2 Alex WtRA7T7NFdYW 3 Jason IGr0ZhaCbojD wp_rsvp id accepted ...
  • 145
0 votes
1 answer
15 views

Merge meta_value's into a single row and then loop

I have a query where I want to merge values from the wp_users and wp_meta tables, including the meta values of a given meta key. This key could have multiple entries. SELECT u.id, (select ...
  • 113
-1 votes
1 answer
68 views

Weird WP -Cli Error Connection Refused

I have a rather of wp-cli problem. I am using wp-cli to import a db from my test server into my staging server and even though the import is successfully and everything seems to be working correctly ...
  • 153
0 votes
1 answer
27 views

Can't send form data to wpdb when URL has query string

I have a table called wp_invites which contains a list of invitees. This table contains a column called reference, which is added to the URL as a query param in order to customise their invite (i.e. ...
  • 145
0 votes
1 answer
28 views

query_vars doesn't return query string (trying to get data from $wpdb)

I have a ref query string which matches rows in my wp_invites table. In my wp_invites table, I have the following columns: lead_name reference Let's assume here is one of the rows: Lead name: ...
  • 145
1 vote
1 answer
35 views

3 queries to update WordPress

I have been out of the game for a few years so this is difficult. I remember that there were 3 queries that I used inside CPanel when moving a site. they would update the database name and table ...
  • 1,353
0 votes
0 answers
13 views

SQL query to rewrite all media URLs to end with .webp

I have manually converted all media files within the 'uploads' folder to .webp, I have maintained the folder structure, every .webp image remains in the same folder its predecessor was. How do I ...
  • 13
0 votes
0 answers
34 views

SQL get last entry of a specific gravity form

I have a ROI calculator that needs to show the results as a graph. I am using the Visualizer Plugin, which allows for chart data to be populated by the db. I need a SQL query that will get the last ...
0 votes
0 answers
19 views

How to get the sum of each post with the same date

here, I have a table that shows the post with duplicate date: here's my query to show all of this $user_info = get_userdata(get_current_user_id()); $username = $user_info->user_login; ...
  • 13
0 votes
1 answer
529 views

SQL Query to get post_id from wp_posts and and meta_key(s) from wp_postmeta

I have a custom post type called media_coverage and need to export via PHPMyAdmin some of the data in that post type that is in wp_posts (post_title) and also in associated wp_postmeta (meta_key) keys....
0 votes
0 answers
45 views

Search results always returns "No results" no matter what

pre_get_posts hook that never works I used the following code both in functions.php of my theme and in my custom plugin in the "after_theme_setup" hook (pre_get_post code only as it is alot ...
0 votes
2 answers
123 views

How to use orderby on meta_value when using Pods custom database table storage

I'm struggling to understand how I can use pre_get_post when the post's metadata is not stored in the wp_postmeta table. I use Pods (https://pods.io) to create custom post types with custom fields, ...
0 votes
0 answers
15 views

Adding CASE in WP_Query

How can we write this query using WP_Query select wp_posts.ID , wp_posts.post_title, wp_postmeta.meta_key, ( CASE WHEN wp_postmeta.meta_key = '_end_date' THEN wp_postmeta....
  • 1,226
0 votes
1 answer
18 views

WP_Query: How to get results from both meta_key options?

I have the following WP Query: if(isset($_GET['scope']) && !empty($_GET['scope'])) { $scope = $_GET['scope']; } else { $scope = ''; } $foo = new WP_Query([ 'post_type' => '...
0 votes
0 answers
35 views

how to delete in phpmyadmin sql - all users with certain condition and all dependencies

I have in my wordpress website a bunch of pages that has mydomain.com/author/gertielamrertyk/ can someone help me create an sql that will delete all users with certain condition (in my case it is a ...
  • 61
0 votes
1 answer
39 views

Wordpress can I manually add columns in users table and display it in the default manage user plugin and registration form? [closed]

How would I go about doing this? Thank you!
  • 1
0 votes
1 answer
42 views

dynamic page using php from sql database

The Problem I am really struggling to get wordpress to generate a page dynamically based on the content of a database. The Context I have a sql database which contains unique slugs and Ids, and I am ...
0 votes
0 answers
19 views

Sql query does not work well

I have a problem with a SQL query in wordpress. I create a query that return product_ID of products that have one or more attribute. I have highlighted my problem. I want to displya the product that ...
1 vote
0 answers
19 views

WordPress is not creating table in database after activating plugin,

I struggled with this a long time! Can anyone help me? My plugin is not creating a database table once activated. The following code is in the main plugin file. function woocq_activate() { global ...
  • 11
0 votes
1 answer
47 views

custom tables in wordpress Database? (can i just create them with sql?)

i just want to create a custom Table in my WordPress database and i saw many php functions to deal with that my question now is : can i just create them with an sql command and for what do i need to ...
0 votes
0 answers
287 views

SQL query - get a featured image's alt / alternative text

I am writing some SQL queries to get post data out of a database for certain posts (so WP functions are not an option). I am trying to get post IDs, post URLs, post featured image URLs and associated ...
  • 31
0 votes
1 answer
38 views

REGEXP_REPLACE in post_contet

So, basically, I want to remove trailing slashes from specific domain urls. For example: https://www.example.com/here/postname/ into https://www.example.com/here/postname I have 10.4.21-MariaDB which ...
0 votes
1 answer
480 views

How to left join meta in queries [closed]

I have a query something like //read products with thumbnail and sku SELECT products.*, pm1.meta_value as sku, p1.guid as thumbnail FROM `wp_posts` as products LEFT JOIN `wp_postmeta` as pm1 ...
  • 111
0 votes
0 answers
28 views

get_terms with specific id order

I have the specific query $queried_object = get_queried_object(); $taxonomy = $queried_object->taxonomy; $term_id = $queried_object->term_id; $isActive = 0; $postTerms = get_terms( [ 'taxonomy' =...
  • 3
-1 votes
1 answer
192 views

wpdb prepare without placeholder

Recently, I found out why there are a lot of PHP Notice on my debug.log. It is because of wpdb:prepare needing placeholders. Documentation says that I need to do: $wpdb->get_results( $wpdb->...
0 votes
1 answer
46 views

Sql formatting for post data within function

I'm calling a function through ajax in my site, and within the function that's being hit I'm taking the data (in this case it's a search term) and putting it into LIKE statements in sql: $...
  • 113
0 votes
2 answers
142 views

Wordpress SQL LIKE request doesn't work for fields with special symbols

In WordPress I make SQL-requests to the database but LIKE request doesn't work correctly. Actial value of meta_value field in the database is such string: a:1:{i:0;s:9:"full-time";} if I ...
  • 111
0 votes
0 answers
31 views

This code is supposed to only allow user to be authenticated if accountVerified is equal to 1, but it still allows user to be authenticated otherwise

global $user_id; global $wpdb; if(is_user_logged_in()){ header("Location:https://www.recovermenow.co.uk"); } if(!$user_id){ if($_POST){ $...
0 votes
0 answers
28 views

Why is my insert row only inserting the final row from the loop into the database rather than just inserting one

<?php session_start(); if(is_user_logged_in()) { global $wpdb; $id = get_current_user_id(); $recoveryID = null; // $results = $wpdb->get_results('SELECT * FROM ...
0 votes
0 answers
114 views

Unknown column 'wp_posts.ID' in 'field list

I'm getting WordPress database error: [Unknown column 'wp_posts.ID' in 'field list'], but column does exist, can someone please tell me what I'm doing wrong? SELECT * FROM wp_posts WHERE ID IN( ...
  • 146
0 votes
0 answers
66 views

Counting Posts with multiple taxonomy and terms condition using MySQL and AJAX

I am trying to get the number of posts with multiple taxonomy and terms using MySQL and AJAX. but I cannot get the desired result with my query. I derived my query in this wpdb query and sadly it ...
0 votes
0 answers
38 views

Change pure SQL database query to WordPress post query?

I am trying to query posts that are nearby a given (lat/long) location. I have found this working SQL query, but this won't provide me flexibility to alter the queried later on, since I am not really ...
  • 230
0 votes
0 answers
144 views

Database SQL query error

I am trying to run below query. $sql = "SELECT * FROM `wp_podsrel` WHERE `related_item_id` =$user->ID AND `pod_id` = 17 AND `field_id` = 25"; $results = $wpdb->get_results($sql) or ...
  • 407
1 vote
0 answers
119 views

Sorting events by descending date, and ascending time if multiple events on a date

UPDATE: Solved with the answer below. $past_events = array(); $past_events_sql = $wpdb->get_results( $wpdb->prepare( "SELECT p.ID, from_unixtime(m.meta_value,'%%Y-%%m-%%d') ...
1 vote
1 answer
129 views

How To Fix WP Query Returns Results But Shouldn't?

I have a WP Query that should return no results, but instead seems to be returning items. I'm guessing the null result is being interpreted as "return all results" but I'm not sure the ...
1 vote
0 answers
77 views

How to change post published date to today date with SQL

How to change already published post date and time to current date and time using SQL. I have a solution for the year but I don't know how to change the whole date to the current date and time. UPDATE ...
  • 37
0 votes
0 answers
164 views

Bulk delete WordPress Post and all metadata, etc using SQL query

Is it still possible to bulk delete WordPress post and it's meta data, etc using an SQL query, I tried using some queries from years ago but didn't work. How can I do this?
0 votes
0 answers
62 views

SQL command to delete "pending comments" doesn't work...?

This is the SQL command: DELETE FROM wp_comments WHERE comment_approved = 0 This, as you can see in the screenshot below, says that the operation was executed ok but no rows affected....which is odd ...
  • 983
1 vote
1 answer
151 views

WP Optimization: Removing Orphaned wp_options (especially the autoload ones)

Is there no mechanism which purges old options from the DB? I tried a few plugins in the past and I found out that there are a few pretty long option strings which are set to autoload but IMHO not ...
  • 152
0 votes
1 answer
70 views

Why line returns are not reapply after doing esc_sql?

I trying show data from my database. This data was escape by esc_sql like bellow. But when I use it in echo, line-returns are print as normal chars ('\', 'r', '\', 'n'). $data = esc_sql(" ...

1
2 3 4 5
16