Skip to main content

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).

274 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
5 votes
2 answers
782 views

Extending WP_Query — Optimise SQL query

I'm storing posts, a user follows in a custom table that has the columns id, post_id and user_id. To fetch posts that a user follows I have extended the WP_Query as follows: class ...
John's user avatar
  • 1,449
4 votes
0 answers
89 views

my function doesn't return my post from today

I'm using gravity form to create some custom post type - as events. Everything is working great, There is some date field to setup the event from x to y date. ALl of this working great. However, I ...
tibewww's user avatar
  • 297
2 votes
0 answers
1k 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 ...
Klaudio's user avatar
  • 21
2 votes
1 answer
95 views

Cron While Editing Post

I have a multi-author blog, on which there are two schedule cron functions. The first function moves all public posts in the pending status after 365 days: if( ! wp_next_scheduled( '...
Claudio's user avatar
  • 21
1 vote
1 answer
37 views

Deleting WordPress posts and media files based on author via MYSQL database

I would like to delete some of the posts in WordPress between a period based on the author via MYSQL database. I have difficulty identifying the WordPress tables and their relationships to perform the ...
Lal Prasanth's user avatar
1 vote
0 answers
34 views

How to properly prepare a column name if passed to a stored procedure?

I've figured out that I can use %i with $wpd->prepare() to escape identifiers like column names. The thing is that the query I'm preparing is a call to a stored procedure like this. I want the end ...
Compjeuter's user avatar
1 vote
0 answers
38 views

Publishing failed error due to "CAST()" in post

When updating a post about the SQL functions CAST and CONVERT, the post fails to update because I use parentheses after the word "CAST" (ie CAST()). It does not happen if I add parentheses ...
David_Hercules's user avatar
1 vote
0 answers
21 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 ...
Mushy's user avatar
  • 11
1 vote
0 answers
350 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') ...
Jen Abella's user avatar
1 vote
0 answers
126 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 ...
Puneet's user avatar
  • 47
1 vote
0 answers
206 views

Bulk-create posts from SQL database

I'm new in this forum and fairly new to Wordpress as a whole, so I hope I will abide by all written and unwritten rules when posting this. I have an SQL database with around 4,000 posts from an old ...
Ran_Char's user avatar
1 vote
0 answers
59 views

Editing the default wordpress search

My wordpress sites search function is not relaxed enough for my liking. I want it to match more items and be less strict. How would i do this? I was thinking it would to do a pre-get posts filter but ...
imJustAskingMan's user avatar
1 vote
2 answers
64 views

Difficulty importing my live site to local

Im using local by flywheel, Here are the steps i have taken so far: Installed local by flywheel and created a site called stage Downloaded the website from CPanel and also the SQL database Imported ...
iheartex's user avatar
1 vote
0 answers
814 views

Sql query to get all metadata for a post

I have three tables in my database one is users table the other is posts and wp_post meta. In the user table I have all the user details . In the wp_posts table I have different posts types . I want ...
technical Zillancer's user avatar
1 vote
1 answer
143 views

Problem with creating tables for Plugin

I hope someone can help me. I try to execute this code to install the tables for my Plugin. But for some reason it doesn't work (Doesn't appear in my wordpress database) and I can't find out why. Can ...
Artok Kotra's user avatar
1 vote
0 answers
66 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 ...
Amol Borkar's user avatar
1 vote
1 answer
1k 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 ...
robskrob's user avatar
  • 111
1 vote
0 answers
28 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 ...
Gareth's user avatar
  • 11
1 vote
0 answers
439 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 ...
FooBar's user avatar
  • 444
1 vote
0 answers
32 views

Wordpress WPforms customization

Firstly I would like to apologize because my question may be a little bit nooby. For the educational purposes I am building app to keep several different records in DB and then make custom query from ...
Gašper Štefančič's user avatar
1 vote
0 answers
154 views

WP Query related posts by tags

I want to display related posts ordered by multiple tags. So I need to create a function what will query posts with the most number of tags in common and display them in descending order. But also it ...
Roman Sarvarov's user avatar
1 vote
1 answer
80 views

batch adding posts to a category based on matching regex for title with SQL

I am adding location categories to posts based on keywords in title (with regex), I got it working once, so code is fine the first time, but now get SQL Error (1062) Duplicate entry '4419-268' so I ...
Benedict Harris's user avatar
1 vote
1 answer
455 views

Order by summing multiple values

In a custom post type (products) I want to order products by summing multiple values based on user selection. I use custom taxonomies to filter the products. I could use the orderby meta_value but ...
Christopher's user avatar
1 vote
0 answers
77 views

Wordpress database error: You have an error in your SQL syntax

I am receiving the following error when I try to so a search in my media folder and I don't know how to correct it: WordPress database error: [You have an error in your SQL syntax; check the manual ...
isakellis's user avatar
1 vote
1 answer
150 views

The function can not create a table on MariaDB server

The function works on MySQL server well but it can not create a table on the MariaDB server. What could be the problem? public function create_table() { $current_version = get_option('...
Andrew B.'s user avatar
1 vote
1 answer
99 views

How to extract specific post

I've to extract only the posts where the meta_value does't contain some specific string. I use this code: $query = new WP_Query( array( 'post_type' => 'estate', '...
Eleonora rossini's user avatar
1 vote
0 answers
288 views

dbDelta not creating table (yes, once more)

I KNOW there are other posts relating to my issue, i read all of them and tried to see if the answer would change and tried a few ones, but I can't seem to create my table using it. Here's my code (...
Chuck's user avatar
  • 31
1 vote
0 answers
423 views

Wordpress Database Huge wp_usermeta Table

I have a wordpress site with over than 700,000 users. Each user adds more than 20 rows to the wp_usermeta table ! this is causing very slow queries and the website started to crash, login failure and ...
blugraphic's user avatar
1 vote
1 answer
472 views

How to display user_nicename and usermeta values by custom query in Wordpress?

I am trying to display user_nicename and one of usermeta values where meta_key is description. My query is given below: <?php $querystr = " SELECT * FROM $wpdb->users, $wpdb-&...
Gamer's user avatar
  • 111
1 vote
2 answers
989 views

How to run select query of post with category and tags?

I want to fetch multiple posts with categories and tags currently I'm using this query: $pagesize = 20; $pageNumber = 1; $mysql = mysqli_query($con,"SELECT p.post_title, p.ID, p....
Mohnish's user avatar
  • 11
1 vote
0 answers
95 views

SQL Database, repeated tables?

On moving a site to localhost I noticed there are 150 tables? On further investigation it appears that many of the tables are repeated. For example: siwp206985_wp_wfHoover --> utf8_general_ci ...
Grant Smith's user avatar
1 vote
0 answers
247 views

Changing sort order for presentation by Jetpack infinite scroll

I have been able to use WordPress filters for posts_join_paged, posts_where, and posts_orderby to create a query that presents a set of artists where only artists who have a last name listed in the ...
EFC's user avatar
  • 123
1 vote
1 answer
950 views

Create table from array with prepare

Is it possible to create a table with the wpdb::prepare function? I read the documentation and tried to find examples but there where none that helped me. Even creating a table with prepare doesn't ...
MattWithAHat's user avatar
1 vote
1 answer
269 views

Q: How to pull data from custom table to populate zustomizer setting/control select options

I am trying to create a select box/dropdown menu in the Wordpress theme customization area where the options are to be extracted from a column called "alias" in a table named "wp_revslider_sliders" ...
user2286485's user avatar
1 vote
0 answers
417 views

Risk of sql injection for custom search form

In my theme I have got a custom search form in header like this: <form role="search" method="get" id="searchform" action="<?php echo home_url( '/' ); ?>"> <input type="text" name="s" ...
Antony's user avatar
  • 109
1 vote
0 answers
49 views

SQL to migrate post types to taxonomy

It's been about 5 years since had to touch a database so please bear with me. I've just taken over a site that has posts split up by post types, and I need to merge all those posts into the default ...
Niels's user avatar
  • 524
1 vote
0 answers
598 views

Optimizing Wordpress Queries - Removing Group By ID

I'm looking to transform a few queries that I'm running through get_posts into direct MySQL queries, in the hopes of optimizing them further. I see that my initial get_posts query, once built and ...
Prusprus's user avatar
  • 111
1 vote
0 answers
60 views

Restose content from revisions - sql query

How i can restore all posts to the closest revision to a particular date via sql query?
h404's user avatar
  • 11
1 vote
1 answer
988 views

How can I combine one field using wpdb and group by?

I have the following code in my functions.php where I'm trying to group the quantity sold from woocommerce orders into the variation selected on the product. My query is: $uvuorderposts = $wpdb->...
user81828's user avatar
1 vote
1 answer
704 views

Order a custom post type admin screen by a second custom post type title

I have two custom post types: Products and Brands. The Product slug is 'eproduct'. The Brand slug is 'brand-listing'. On the Product admin page, I have added a custom column that lists the Brand ...
LeonardShelby's user avatar
1 vote
0 answers
2k views

Include data from custom table in WP_Query

I'm building an Estate Agent website. They have a system where they add their available properties and sends them all to the main property portals. As part of this, the system also sends all the ...
elmediano's user avatar
  • 111
1 vote
0 answers
2k views

SQL query equivalent to WP User Query

I have the following WP user query code: //Get all users sorted by whatever $sorted_users = new WP_User_Query(array( 'orderby' => 'meta_value', 'meta_key' => 'satisfaction_rating', '...
Thought Space Designs's user avatar
1 vote
1 answer
190 views

How change user type from contributor to author

I have 2058 users who are contributors. I need to convert their role to author. How can do it by SQL?
Luisa DAmico's user avatar
1 vote
2 answers
89 views

Better way to migrate to server?

Migrating between local and server with Wordpress (SQL) is a bit time consuming, and I'm wondering if there is a better way to do it. With Drupal, there is a module called BackUp&Migrate, which ...
Guit4eva's user avatar
  • 211
1 vote
0 answers
117 views

Pull data and display as rows and columns

I am a noob when it comes to pulling data from tables and fields of a WP database so I'll explain it as best as I can without it running into a thesis. I have a table called WP_answer. In that table ...
Rhinoz's user avatar
  • 11
1 vote
0 answers
335 views

delete duplicate comments

I found a solution for this a long time ago. Here is the code: <?php require_once('wp-config.php'); global $wpdb, $comment_content, $comments,$comment_ID; # First select all comments $query = "...
Shady M Rasmy's user avatar
1 vote
0 answers
972 views

Remove posts inside pre_get_posts using a custom query

I need to remove posts from admin listing, if their last child post author is different than the parent post author. I was hoping to use pre_get_posts, but can't figure out how to do this. Here's my ...
user1049961's user avatar
1 vote
0 answers
84 views

Is there a WP function to get taxonomy name from taxonomy_term_id?

I need to get the taxonomy name from the taxonomy_term_id. I am currently using the following to get it: global $wpdb; $term_taxonomy_table = $wpdb->prefix . "term_taxonomy"; $taxonomy = $wpdb-&...
Gixty's user avatar
  • 1,097
1 vote
0 answers
105 views

Genesis framework comments broken?

I got a really weird problem. Im using a Child theme which using the Genesis framework. I was using Akismet plugin to stop the spammers and it was workin just fine. Recently i just made a comment by ...
user3161236's user avatar
1 vote
0 answers
396 views

How to import a Typo3 database to a wordpress site?

I have a SQL database export from a Typo3 site. Does anyone know or have any experience of dealing with these cases?
Ingvi Jónasson's user avatar

1
2 3 4 5 6