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
11 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
22 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
13 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
15 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
12 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
59 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
25 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 ...
0
votes
0answers
33 views

How can I convert this SQL query to delete duplicate posts by specific meta_value instead of post_title?

This query works exactly as it should to DELETE all duplicate posts by post_title for my custom post type: $sql = " DELETE a.* FROM wp_posts AS a INNER JOIN ( SELECT ...
0
votes
0answers
10 views

Get adjacent post data, ordering by custom field values (by Wp-query?)

I want to build a custom version of the adjacent-function of wordpress post. I have two custom field values for each post, my layout is the following: metafield1 value 1 & metafield2 value 1 | ...
0
votes
1answer
16 views

DB_HOST - is LOCALHOST speedy than domain name? [on hold]

I am interested, on some hosting(although they are paid hostings, and even the domain.com DNS nameservers are pointed to that hosting), you have to insert: mysql.domain.com (instead of: localhost) , ...
0
votes
1answer
39 views

SQL Error wp_commentmeta - incorrect table definition

I'm trying to import a database and wonder how I can stop getting the following error? "#1075 - Incorrect table definition; there can be only one auto column and it must be defined as a key " ...
0
votes
0answers
16 views

Problems with database query where two metavalue-key pairs meet condition

I've been trying to put together a database query where the different meta_values of two different meta_keys match the query. One example would be: delivery_date is '2015/06/11' AND supplier is ...
0
votes
1answer
53 views

Sort users by “birthday” using WP_User_Query

I have created user meta that holds user birthday (birthday). birthday is date field. Now i am trying to figure how to sort (get) all users that have birthday based on specific month. I have ...
0
votes
1answer
34 views

MySQL swap one table for another?

So I have a situation with this WordPress site I'm doing where I have to swap the positions of my featured images. I have two per post thanks to the Multiple Post Thumbnails plugin, but now whatever ...
0
votes
1answer
18 views

wpdb->get_var always returning 0

I am trying to run this statement: global $wpdb; $amt = $wpdb->get_var($wpdb->prepare("SELECT SUM(amount) as amt FROM wp_pay_table WHERE postid = %i", $pid)); ...but $amt always comes out as ...
0
votes
0answers
12 views

Show different content in the same URL

I have a blog powered by Wordpress. I need to show different contents in a same webpage according to the date. Say I have few posts with the url format: domain.com/post-01022015, ...
1
vote
1answer
38 views

Auto-update tables from database

On my WordPress homepage I would like to have a table that can auto-update based on database changes at a given time period. I am trying to find the best solution to this problem, weather I code it ...
6
votes
2answers
95 views

Whats the difference between post_limits and pre_get_posts?

Because of the lack of documentation about post_limits, its hard to learn more about this function and when to use it. Never used it before or seen it used so maybe its not to be used? function ...
0
votes
0answers
47 views

phpmyadmin sql error when importing database

i get this error when i try to import my wordpress database from wampserver "localhost" to my live site on the internet. MySQL said: Documentation 1064 - You have an error in your SQL syntax; check ...
0
votes
1answer
23 views

Export Posts with specific custom fields by sql

My development site has posts with custom fields. Meanwhile my live site has more posts added while I'm working on my development site. Now I want to export posts with specific custom fields from live ...
5
votes
2answers
146 views

Optimize Wordpress Query that take 5 seconds to execute

I have a large wordpress database: rows in key tables: 730K wp_posts 404K wp_terms 752K wp_term_relationships 27K wp_term_taxonomy 1.8 Million wp_postmeta The issue is that I have a query ...
0
votes
0answers
38 views

Function is creating too many queries

I have code that displays a list of categories and orders them by the number of ACTIVE posts in the category. This is determined by comparing the custom field of due date against the current date. If ...
0
votes
0answers
27 views

How to optimize get post query

I have a dynamic Wordpress site with large number of posts (almost 2 millions), and need to optimize custom archive search query. This is what I'm using now and it takes ~0,5s (standard query_posts() ...
0
votes
1answer
29 views

Why my query does not run with prepare

Hi Below is my query and it works with prepare keyword on the localhost but whenever I use prepare keyword with my queries on live server the data does not show up and as soon I remove prepare from ...
0
votes
1answer
45 views

How to filter sql only for a specific post type

I have been trying to join a custom table with a regular wordpress query, but only under a specific condition (a specific post type). I have a single-event.php template that runs the main query, and ...
0
votes
0answers
41 views

Change permalink , keeping old structure with date

Currently on our website we have the /date/postname permalink structure with quite a number of posts. For SEO purposes we want to change it to /postname permalink structure but we want to keep the ...
0
votes
0answers
12 views

How to Use WordPress SQL Database on Sub-domains or Directory

I have a domain website.com in English and want to translate a directory to Spanish website.com/es taking exact content from website.com Question: How can I use same database on this directory?
0
votes
1answer
13 views

How to set up prepared query using IN statement

I am a tad bit confused on how I would set up a SQL IN statement using a prepared query. Here is the code: $in = implode(',', array_fill(0, count($product_ids), '%d')); $results = ...
0
votes
2answers
186 views

How to query the WordPress database to get posts of a certain custom post type, taxonomy and field?

I have a custom post type named store and I have a custom taxonomy city, I also have a meta box with a field that is stored with update_post_meta( $post_id, 'store_postal_code', $postal_code ); it ...
0
votes
1answer
686 views

Add special meta box to custom post type

I have managed to add a meta box to my custom post type (see code below) Now I need to add another meta box. With this box I want to display / edit a value from another table called ...
0
votes
1answer
34 views

Clean up very big and very dirty database

I'm trying to clean up a database in order to move a website from a server to another. Database is more than 1gb, mostly posts revisions and spam comments. Is it safe for instance to do something ...
0
votes
1answer
54 views

Wordpress Custom Search By Alphabet and order by asc and sesc

I am new to word-press but i can easily work on core php and other mvc framework,acutally i want to add custom search for only subcategory post. The search will with below Search post By old to new ...
0
votes
0answers
57 views

How can I avoid duplicate primary keys in SQL import?

I have two sites I'm trying to merge. Site 1 has 1500 products in a custom post type, with associated meta and an attached featured image. Site 2 has 250 products in the exact same custom post type, ...
1
vote
1answer
29 views

Are database queries created using WordPress filters protected from SQL injection?

I'm using the WordPress 'posts_where' filter (https://codex.wordpress.org/Plugin_API/Filter_Reference/posts_where) to alter my queries as below: function filter_my_search($where=''){ ...
0
votes
1answer
32 views

Can not manually create a database ( db, user, pass ) for a plugin

So I was working on a plugin and I needed to cache some third party API access, and I needed to manually create a database upon plugin activation or upgrade. The caching stuff needs a database host ( ...
0
votes
1answer
68 views

Custom database query to validate data

I cant find any syntax for custom queries, use of $wpdb is new to me so can anyone help me solving this?? if(isset($_POST['submit'])) { global $wpdb; $tablename='wp_form_subscribe'; $myrows = ...
0
votes
0answers
25 views

Insert query not working for non-logged in user

I am trying to create a function for count post views. for this i have added code in my theme function file. Here is my code: function processpost_views( ){ global $user_ID, $post; ...
0
votes
1answer
30 views

WPDB SQL Ignore `post_status` Parameter

I use this SQL statement: SELECT * FROM wp_posts LEFT JOIN wp_term_relationships ON ( wp_posts.ID = wp_term_relationships.object_id ) LEFT JOIN wp_term_taxonomy ON ( ...
0
votes
1answer
31 views

Sum of Custom Meta written by Authour

I have a custom meta call post_views_count that collects the views of all posts... I want to create a query that pulls in all posts by a certain author, gathers the custom meta for post views and ...
0
votes
0answers
39 views

Link wordpress with a SQl + MongoDB + .NET

This may sound a bit crazy, I have a website using different DB, One SQl; one MongoDB, and a .net API I would really really love to be able to move this to a wordpress installation ( or Magento). ...
0
votes
0answers
141 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 ...
-2
votes
1answer
60 views

If meta_key exists then don't select this post?

I'm trying to select all posts EXCEPT ones with a meta_key somekey. SELECT * FROM wp_posts JOIN wp_postmeta ON wp_posts.ID = wp_postmeta.post_id WHERE meta_key != 'somekey' But this is still ...
0
votes
0answers
22 views

Adding Database Tables for Reviews functionality that incorporates Tags/Categories

I'm wanting to build onto to the Wordpress database in order to give myself the functionality to create/retrieve customer reviews based upon tags/categories. More specifically, the reviews are not ...
0
votes
1answer
65 views

Alter the main search query to search posts by coauthor user name

I am using the Coauthors plugin: https://wordpress.org/plugins/co-authors-plus/ I have written some SQL in order to grab posts from authors whose display name matches the search query when searching ...
0
votes
1answer
11 views

Creates only one table and not the other

I have this function to create two tables when I activate the plugin. Only the wp_wpt_stats table are being created and not the wp_wpt_list. I know the dbdelta is picky, but I can't see what I'm doing ...
1
vote
1answer
77 views

problem with sql query in wordpress plugin

I've got this and I dont know why its not working. It's not returning the ID from the first query so I can use it in the 2nd query. Nevermind the REFERER, its an external link it will refer from. ...
0
votes
0answers
190 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
2answers
90 views

Complex WP SQL Query

I have tried the following SQL query without any success. Can anybody that have a better understanding of SQL help? Here is what I am trying to achieve: Get a list of all main events (ME) where the ...
0
votes
0answers
59 views

Add a custom field via PhpMyAdmin to all posts and pages avoiding duplicates

I have about 200 pages and 400 posts on my WP site. And I need to add one custom field (sidebar_config: left-sidebar) to all pages and posts. I have this for SQL query in PhpMyAdmin: INSERT INTO ...
0
votes
1answer
52 views

SQL error on restoring database

I am running a database backup -- a 7 MB SQL -- using the phpMyAdmin Import function -- and getting an error, whose text doesn't really show where the problem is. MySQL said: Documentation #1064 - ...