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

253 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
4
votes
2answers
629 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 ...
3
votes
0answers
79 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 ...
2
votes
0answers
511 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 ...
2
votes
1answer
87 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( '...
1
vote
0answers
15 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 ...
1
vote
2answers
24 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 ...
1
vote
1answer
37 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 ...
1
vote
0answers
25 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 ...
1
vote
0answers
17 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 ...
1
vote
0answers
137 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 ...
1
vote
0answers
19 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 ...
1
vote
0answers
56 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 ...
1
vote
2answers
2k views

get all posts in custom post type by ACF field value

I have a custom post type with custom fields(advanced custom fields plugin). one of the custom fields named program_id. i can`t understand how to get all of the posts in that CPT where the ACF field ...
1
vote
1answer
55 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 ...
1
vote
1answer
332 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 ...
1
vote
0answers
66 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 ...
1
vote
1answer
84 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('...
1
vote
1answer
59 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', '...
1
vote
0answers
268 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 (...
1
vote
0answers
219 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 ...
1
vote
1answer
360 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-&...
1
vote
0answers
86 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 ...
1
vote
0answers
190 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 ...
1
vote
1answer
578 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 ...
1
vote
1answer
212 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" ...
1
vote
0answers
291 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" ...
1
vote
0answers
44 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 ...
1
vote
1answer
750 views

UPDATE on SELECT results. A SQL query to swap Author with Meta Box value

I inherited a project where, for some reason, the previous developer make a custom post type for authors and a custom select listing all those authors cpt titles in the post edit screen. This led to a ...
1
vote
0answers
522 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 ...
1
vote
0answers
58 views

Restose content from revisions - sql query

How i can restore all posts to the closest revision to a particular date via sql query?
1
vote
1answer
706 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->...
1
vote
1answer
456 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 ...
1
vote
0answers
1k 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 ...
1
vote
0answers
1k 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', '...
1
vote
1answer
178 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?
1
vote
2answers
81 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 ...
1
vote
0answers
106 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 ...
1
vote
0answers
273 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 = "...
1
vote
0answers
760 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 ...
1
vote
0answers
76 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-&...
1
vote
0answers
90 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 ...
1
vote
0answers
343 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?
1
vote
0answers
2k views

$wpdb->insert() does not Insert record in a table

I'm trying to understand and get hold of the $wpdb global object but can't seem to make it work. Basically, I'm trying to insert a single record into a custom table in wordpress DB. Instead of ...
1
vote
1answer
319 views

Attempt to improve WP search, can someone check my SQL query?

I'm stumped. I've done a bunch of work to filter what posts get pulled in a WP search and then even more work sorting those after they're pulled from the DB. My main problem now is getting results ...
1
vote
0answers
118 views

Meta Query And/Or

My question is very similar to Meta Query with AND & OR? . This question was answered in 2011 by @Otto. With the exception that my logic is different. I want to query, for example, posts with ...
1
vote
1answer
5k views

Custom SQL Query: Get all posts with category id and a concated list of tags on each post

I am trying to select all posts from a WordPress database, include few fields on each post, but most importantly I would like to also select the "category id" or each post, and ALL the tags that ...
1
vote
1answer
4k views

Get posts under a category with SQL

How can I retrieve posts under a category with plain SQL with out using WordPress native api's like get_pages? My Wordpress table wp_terms contains a term named Restaurants. I want to list the post ...
1
vote
2answers
91 views

Wordpress SQL Issue not returning correct reselts

So, I have been working on an SQL query involving the users and usermeta tables in wordpress. I am not getting the correct results. I have the following query written SELECT * FROM ...
0
votes
0answers
6 views

How to query results for post_title and Custom Post Type/ACF field pivot query

I have a custom query that needs to match a search term to a custom post type of event by post title and by an ACF field host and then filters out events that have passed the current date to a REST ...
0
votes
1answer
12 views

I want to get on those users their meta value are like “AGENT” .. but this query is not working

SELECT display_name FROM $wpdb->users WHERE id IN (SELECT user_id from $wpdb->usermeta where meta_value LIKE '%agent%')

1
2 3 4 5 6