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)

0
votes
0answers
17 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 ...
0
votes
0answers
21 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 ...
-2
votes
1answer
29 views

Restore Backup of my site

I was using a site but can not continue it and the hosting and domain expired. But goDaddy gave me a backup file for future reference. Now I want to recover my site. But within the zip goDaddy gave me ...
0
votes
2answers
35 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
29 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
38 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
14 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
17 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 ...
2
votes
2answers
76 views

List of posts by day of the week

I have Radio with programs and they are associated to day of the weak. Example: 1-Program Disco Nights plays at Monday and Friday 2-Pragram Crazy weekends play only at Sunday 3-etc 4-etc ...
0
votes
1answer
21 views

Update user_login, user_nicename, and display_name

I have about 600 user records I've imported from a WooCommerce site, but they have the email as their username and I need their username to be first.last So I'm trying to find a SQL way to update all ...
0
votes
1answer
53 views

cron job to auto delete posts of a specific post type older than x days

I want to delete all posts of a specific post type (in this case "vfb_entry") that are older than 60 days. The cron job should run once a day. I have the following code but it's not working if I ...
1
vote
0answers
18 views

Restose content from revisions - sql query

How i can restore all posts to the closest revision to a particular date via sql query?
0
votes
1answer
24 views

Insert multiple checkbox values

I am trying to insert multiple checkbox values in my database with the function insert() of WordPress, but it don't work same when I use a SQL request. Although my table exist I really don't see where ...
0
votes
1answer
29 views

Custom Query - Based on user input

I'm working on displaying suggestions to an input, assisting the user. I'm using the included jQuery suggest. That's loading - and through ajax I'm using a custom SQL query and can see it's ...
0
votes
0answers
14 views

Editing a Wordpress SQL table in Phpmyadmin, however its not saving

I'm trying to edit the wp_options table in Phpmyadmin, I can edit it fine using inline editing or the edit feature. Each time I log into phpmyadmin I can see the value has changed to the one I edited. ...
0
votes
0answers
37 views

I want to query for the 'post' and 'attachment' in wordpress using SQL query

How do I write a SQL query which will allow me to query for the 'post' and 'attachment' at the same time in MySQL? I am trying to get this information from the wordpress 'Posts' table. Please see my ...
0
votes
1answer
54 views

A faster way to query custom post types with multiple conditions?

I am using a lot of custom post types (CPTs) with custom meta and so far I have been using queries like the below, to get for example all events in CountryX that happened in 2014: <?php global ...
0
votes
2answers
27 views

get_results() query not working only when entering strings

I'm trying to send a query to a database, WHERE works fine if I'm querying for a number but not for a string. Example, if I try: $all_pages = $wpdb->get_results('SELECT post_title, guid FROM ...
0
votes
1answer
24 views

Find by post_meta, then sort by post_meta, then sort by date (wp_posts)

I have a custom meta field that I find a list of posts from. This custom meta is a numerical attribute (1-10) and I need to sort by 1-10, but I also need to sort by post date. So if two items are ...
0
votes
0answers
31 views

SQL / Select users depending on meta value - meta keys, sorted by a meta value - meta key not in the select

I'm trying to select users with one of several meta keys corresponding to a meta value, and to sort the results by a meta value associated to a meta key which is not in the select. In other words, I ...
0
votes
1answer
128 views

Inserting Post Meta From SQL

I'm trying to get post meta to be updated/replaced with $wpdb and running into issues. I have working SQL, but cannot get it work when coding it up for my WP plugin. Extra note: The post meta being ...
-2
votes
1answer
44 views

Custom Query for wp_posts using wp_postmeta

In postmeta lets say meta_key = 'count' and meta_value = '5' meta_key = 'count' and meta_value = '6' meta_key = 'count' and meta_value = '7' now i want to get all post WHERE meta_key = 'count' ...
0
votes
0answers
43 views

Exporting wp_posts and wp_postmeta as a single table entry per post

I’m trying to export all posts of a certain type (to run a report), and all the associated post meta data. I want a single entry for each post, with all associated meta data, e.g. “Middle Name” as a ...
0
votes
1answer
28 views

Custom post order when using OR relation

I have a custom post type named Faculty. They can be any of the type MCT, MLT, or MT. MCT -> A, B MLT -> C, E MT -> C, D I want to list all MLT and MT faculty on a page in order by last ...
0
votes
0answers
25 views

wpdb->update update the entire table instead of one row

I'm trying to use the update function of wpdb, like this: $wpdb->update( 'protocol_data_list', array( 'used' => 1 ), array( 'cod_protocollo' => $_POST['numero_protocollo'] ), ...
0
votes
1answer
32 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 = ...
0
votes
0answers
55 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 ...
1
vote
1answer
56 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 ...
0
votes
1answer
59 views

What does the $posts_join filter join to?

I am trying to use the posts_join filter to join 2 tables: wp_postmeta to wp_posts. I am a novice at SQL, so I'm not sure if I am confused because I don't understand how WordPress is implementing ...
0
votes
0answers
28 views

Render a Wordpress menu from outside Wordpress?

I would like to render a menu in another system outside wordpress using SQL to fetch the menu contents and some logic to build the actual menu. I turned on mysql logging to see what wordpress was ...
0
votes
0answers
16 views

SQL query to load a menu and contents [duplicate]

I would like to render a menu in another system outside wordpress using SQL to fetch the menu contents. I'm able to find a menu item based on the slug: SELECT * FROM `wp_terms` wt WHERE wt.slug = ...
3
votes
1answer
100 views

SQL Statement generated by WP_Query not producing expected results

I am trying to alter WP_Query on the pre_get_posts action hook, for filtering the posts returned, depending on the built-in category and post_tag taxonomies. I would like that the only posts returned ...
0
votes
1answer
142 views

Add custom argument to WP_Query and modify SQL where clause

I'd like to be able to hook into WP_Query in such a way that I can add a custom argument to my WP_Query like: $q = new WP_Query([ 'my_cool_arg' => [ 1, 2, 3 ] ]); and then access this and ...
0
votes
0answers
20 views

Delete duplicate media in SQL only

I have uninstalled WPML and deleted all WPML tables in the DB. Now, I have duplicate media (one per old languages) in my SQL only (not in the FTP). I would like to delete these duplicates and only ...
0
votes
2answers
45 views

Database SQL Error, Should Work

I'm trying to get my posts to order by radius, and so far i'm struggling, I've been using the following tut by Steve MArks, http://biostall.com/performing-a-radial-search-with-wp_query-in-wordpress ...
0
votes
1answer
64 views

Database Query not working

I've been following a tutorial by Steve Marks which goes throught adding information from posts to a new Database Table as well as the usual postmeta one. However no matter what I try, It will not ...
0
votes
0answers
26 views

Nothing wrong with SQL but still getting an error

I'm developing a plugin and I need to perform a SQL query with GET parameter. The code looks like this: if (!empty($_GET['editDoc'])) { global $wpdb; $id = $_GET['editDoc']; $table_name ...
0
votes
1answer
61 views

Run an update query in a function

I need to run the below in a function, it updates my database if certain conditions are met. I can't get it to work and I can only assume its because of the "SET @newnum" at the beginning. I've ...
0
votes
0answers
70 views

External SQL Database (Login Details) to update wp_users with new users

I have an external database which currently has a Username and Password field, which are plain text (password field not using any hashing). Is it possible for when I update this database that it will ...
0
votes
1answer
43 views

Conditional statement within WP SQL query

I have a form on a Wordpress page posting data to a table called 'members'. I have a second page displaying this data in a table. All is working well. The data is being displayed using: $myrows = ...
0
votes
1answer
118 views

WP User Query get all authors with last name starting with specific letter

I need to program a page to which I pass an initial through the url and it will show all author users whose last name starts with that letter. I would like to do this via WP User Query so that I can ...
0
votes
2answers
57 views

This wp_query will not return any posts and only seems to work with post_status inherit?

I'm having difficulty returning a list of posts. This file is contained in a plugin folder (ultimately I want to have a cron job just run the script here to delete posts with invalid urls in the given ...
1
vote
2answers
86 views

Getting users who registered 360 days from current date

As per the title, what I want to do is run a custom query that (using WP-Cron) will run once a day to check for users who registered exactly 360 days before the current date (don't need time, just ...
0
votes
0answers
78 views

pre_get_posts with custom SQL

I have a scenario where there is a custom form on an archive page. I want to use pre_get_posts to modify what is displayed on the archive page, and show the paginated results. The issue is I first ...
0
votes
0answers
35 views

Insert the same row 3 times

I am trying to developing a plugin for body mass index. I am trying to enter a row while creating table in register_activation_hook. When activation is finished i see 3 same rows in database. Here is ...
0
votes
0answers
31 views

How do I update post based on meta_key in another table?

So I have a function that is called by the wp_schedule_event (cron job) once daily. The goal of the function is to set all posts with a field wpcf-engine-days-to-go that has a value of "0" to a draft. ...
0
votes
1answer
22 views

Sql query returns empty. But not

my sql query returns empty $sql = $wpdb->get_results('SELECT * from table1 WHERE id = ' .$bransId); And im sure that $bransId is not empty. ( i checked)
0
votes
0answers
42 views

Adding left join to sql query

im trying to get some extra data from another table with left join (or may be another join, because one data from one table ). But i couldn't success. Because my query is little bit different for me, ...
0
votes
1answer
135 views

Convert a WP Query into a simpler SQL query to fetch only COUNT of posts

I have this WP Query running for each row in my admin screen for a certain post type: $entry_args = array( 'meta_key' => 'wp_comp_entry_competition-id', ...
0
votes
1answer
115 views

Inner Join user tables to select users with roles

I am trying to view a list of users (who are music artists) with the following function. function show_authors($ltr) { global $wpdb; $querystr = "SELECT $wpdb->users.* FROM ...