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

learn more… | top users | synonyms (1)

1
vote
1answer
12 views

wpdb query on custom table not working

I want to show one custom table from my database on which WordPress is installed. So I googled this code: <?php $results = $wpdb->get_results( $wpdb->prepare("SELECT * FROM ...
0
votes
1answer
18 views

Update field name without losing the value

So I have this photography website using ACF with flexible content. It has approximately 300 posts. Due to requirements, I need to update the name of some fields. I've tried the following query: ...
0
votes
1answer
19 views

Scheduling posts in database

I have more than 100 posts to schedule. I have set the date and the status (future) with a SQL query. But when the time comes the post is not published and in desktop I can read message 'Schedule ...
0
votes
2answers
30 views

WPDB Placeholders and second argument for prepared statements

How can I set placeholder and second argument for that kind of sql prepare $wpdb->prepare( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'attachment' AND ID IN ...
0
votes
0answers
29 views

Storing Unique Data on the Database

I have created a custom table on my database using the code below: function dbcreator_activate() { global $wpdb; $table_name = $wpdb->prefix . "ftbstatistics"; if( ...
0
votes
0answers
16 views

Custom database query with accents returning no results

I have an issue where using accents in my custom database query (wpdb) returns no results. $wpdb->get_results( "SELECT * FROM table WHERE city = 'Montréal'" ); Returns nothing, while ...
12
votes
8answers
65k views

What SQL Query to do a simple find and replace

Whenever I create a new website I first create a staging site on a subdomain like "stage.domain-name.com". After everything works correctly I export the database, open it in notepad++ and do a ...
0
votes
1answer
2k views

Using AJAX to run SQL statement and populate dropdown

I am trying to create a search where the user selects two different bits of data from the database and it then prints some results that meet requirements. I know I need to use AJAX, or something ...
0
votes
1answer
779 views

SQL to update custom post taxonomies

I have a custom post "review". It uses the same categories and tags from default posts, so they share "category" and "tag" taxonomies. But later I changed the "review" register to have their own ...
0
votes
1answer
12 views

wpdb get posts by taxonomy SQL

I need a list of posts of a specific post_type plus the name of a custom taxonomy term. This is what I got so far SELECT p.post_name,t.name as clientName FROM $wpdb->posts AS p, $wpdb->terms ...
0
votes
0answers
24 views

send email to user

I want to send an email to users based on the value of the database. To clarify if the user exceeds the value set in database, send him an email Automatic But I do not know where to write the code in ...
0
votes
0answers
18 views

Function get_results doesn't working

This is very very strange, 'cause when I run this query in my MySQL terminal, works perfectly: Query: "SELECT a.post_id, a.meta_value, a.meta_key, b.meta_key, b.meta_value FROM pdb_postmeta AS a ...
0
votes
1answer
98 views

Get all child comments ids from parent comment id

I want to get all child comments ids from parent comment id. Do i have to write custom sql or can i use get_comments() to achieve the following output. eg 1 I want to get 2,3,4,5,6,7,8 ids from ...
0
votes
0answers
21 views

Limit results of custom query to current category

I have created a geolocation system for a custom post type of services and have been working on a query to limit the results based on address/distance entered by the user. Everything seems to be ...
-2
votes
2answers
524 views

SQL query to check whether a meta key is set or not for a post in post_meta table

Condition: some post have meta_key 'status'. Please help me in with this condition: sql query for those post who don't have meta_key 'status'
0
votes
3answers
51 views

Get all posts from db between 2 specified months

Am trying to get wp posts between two specific calendar month. The problem is, it is a annual year. So month starts from May and ends in Next year April. So each year output should start from May of ...
0
votes
1answer
19 views

Use variable in SQL statement

I have this: <?php $jerseys = $wpdb->get_results("SELECT order_item_id, order_id FROM wp_woocommerce_order_items WHERE order_item_name = 'Mystery Jersey'"); echo "<p>Jerseys</p>"; ...
0
votes
0answers
17 views

Why Do I Still Getting Duplicate Rows in SQL?

I'm creating a Custom Freight System which stores the order and the products requested by the user into the WordPress Database. The Problem When I insert the product into the wp_my_custom_products ...
-1
votes
2answers
1k views

Change Login URL Without Plugin

I want to change the login url of my Wordpress install away from /wp-admin.php I am aiming to do so and am looking at changing the .htaccess file to add in: RewriteRule ^login$ ...
0
votes
2answers
70 views

What to create new post using wp_insert_post, but it repeat the post infinitely

this is my source global $page; $page_exists = $page->post_title; $another_db_user = 'user'; $another_db_pass = 'pass'; $another_db_name = 'name'; $another_db_host = ...
0
votes
2answers
55 views

Wordpress wpdb->insert returns int(0) => doesn't insert anything, no errors!

I am really clueless. I want to do an insertion in my WordPress plugin the problem is it doesn't return any errors nor it insert the stuff! I don't know how to fix this and really need your help. In ...
1
vote
1answer
100 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?
0
votes
0answers
20 views

WP_QUERY with alternating post types and pagination [duplicate]

I want to show both regular posts and a custom post type (event) on the homepage in a single loop. The event post type needs to be ordered by a custom field for the event date and show future events. ...
1
vote
1answer
32 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( ...
20
votes
5answers
43k views

WP_Query with “post_title LIKE 'something%'”?

I need to do a WP_Query with a LIKE on the post_title. I started with this regular WP_Query: $wp_query = new WP_Query( array ( 'post_type' => 'wp_exposants', ...
2
votes
0answers
1k views

$wpdb->get_results(…) returns empty array despite correct query

As title implies, I cannot seem to get $wpdb->get_results to give results. Running the "raw" query is successful, but this seems to be failing for some strange unknown reason. global $wpdb; ...
0
votes
2answers
130 views

How i make a custom sql query for Woocommerce

hello i have an ecommerce with Wordpress + Woocommerce, just yesterday a hacker boy or...i don't know moved all woocommerce products in to the trash.... there are lots of products and default ...
0
votes
1answer
38 views

How to order custom user list columns by datetime?

I am trying to add the ordering options to some custom user list columns I added in the Wordpress admin. This is my code : function mmm_user_sortable_columns_query( $userquery ){ if( 'test_date' ...
0
votes
0answers
32 views

SQL to update custom post field

I tried to update a custom field but I can't to this... I have a custom post that that I used for a fill months. Now I create a new date custom field called "data-edital". On the new posts, I put the ...
0
votes
0answers
28 views

Fast User Query Using SQL vs WP_User_Query

I've found that WP_User_Query() is very slow when dealing with more than 1,000 users and I have decided to use custom MySQL queries. In my code below, I pulled only user_id to make it work faster and ...
0
votes
1answer
388 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', ...
3
votes
1answer
152 views

Sorting a list of posts displayed under a list of associated terms (which should be sorted without initial articles)

I have series of sorting issues on a page that I'm trying to figure out but so far to no avail. Sorting a list of CPT posts which are listed under associated custom taxonomy terms I found this piece ...
0
votes
1answer
34 views

WooCommerce - Order_itemmeta - Need to add meta_keys to table

I need to add 3 meta values to each order_item to the woocommerce_order_itemmeta table. Any suggestions how to create new meta_keys to be included in the table for all order items?
0
votes
0answers
57 views

How to get last order number in Woocommerce and insert next?

I am developing an offline product to retail. This will be sold by a distributor NOT through my website. I have an sequential order reference system based on woocommerce such as 152, 153 etc. I want ...
0
votes
2answers
50 views

Convert a category of posts to a custom post type using (MySQL) queries

I am trying to convert over 2000 posts with a category of hp_operator, to a custom post type. I usually use the "Convert Post Types" (a plugin) for tasks like this but with the amount of posts here ...
14
votes
6answers
17k views

Most efficient way to get posts with postmeta

I need to get a bunch of posts with their metadata. Of course you can't get metadata with a standard posts query, so you generally have to do a get_post_custom() for each post. I'm trying with one ...
0
votes
0answers
31 views

Retrieving meta values from database to CSV

I am working on this database in which the data is serialized and it's in a multidimensional array. I am trying to retrieve the data from WordPress into a CSV file. I read that WordPress automatically ...
0
votes
1answer
23 views

$wpdb query for price in custom field value

A classifieds list site have only 3 criterias when searching products: the common search, category and region (for ZIP, city or full address) It's not enough and I really need to include a basic price ...
0
votes
1answer
19 views

Include post_status check within $wpdb query

I've got a function that returns a count from the database for publish posts that match the product ID to the post meta ID (both are the product type). I've realized this query returns unpublished ...
1
vote
1answer
120 views

What SQL / WordPress queries would need a nonce?

I'm a PHP / JavaScript developer and I'm new to WordPress. Our company's website is build upon WordPress. However I created many custom PHP pages without minding the WordPress framework much. When ...
-1
votes
1answer
45 views

SQL command to convert all tags in lowercase?

I'm looking for a SQL query command to convert every single tag in every post ever used to be converted into lowercase.
0
votes
0answers
18 views

SQL query works only if inclusive

I have a Wordpress website with, say, 5000 articles. I am trying to apply a query to filter all the posts with featured images not listed in some specific categories. I started with: SELECT ...
1
vote
0answers
34 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 ...
0
votes
3answers
36 views

optimise SQL wordpress call

I have this code : $querystr = " SELECT * FROM {$wpdb->prefix}posts INNER JOIN {$wpdb->prefix}postmeta m1 ON ( {$wpdb->prefix}posts.ID = m1.post_id ) INNER JOIN {$wpdb->prefix}postmeta ...
1
vote
2answers
43 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
1answer
35 views

Posts modified in the last 48 hours

I am using the code below to generate posts created in the last 48 hours. function filter_where($where = '') { $where .= " AND post_date > '" . date('Y-m-d', strtotime('-2 days')) . "'"; ...
0
votes
0answers
54 views

SQL in WordPress get_var() not working

I created a few tables in my main WordPress database. Table names are: cards scards I put a plugin that lets me use PHP in pages, I used it in my other WordPress sites successfully but in this ...
1
vote
1answer
26 views

Setup private content for specific users with daily updates [closed]

So I have only found membership plugins which cater for private area where users can access the material after paying depending on their role. I need to make a dashboard kind of area where users can ...
-2
votes
1answer
22 views

Where can I find the SQL to get the most used information by wordpress database?

I tried to google "wordpress sql to get post url" and I was pretty astonished I couldn't find any resource sharing the SQL code to join the wp_post table with the table containing the permalink. How ...
4
votes
4answers
9k views

Pagination with custom SQL query

I have my own SQL string to select Custom Post Type posts with specific WHERE clause. I've used the offset and limit to return appropriate posts depending on a page being displayed. That's working ...