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
32 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
21 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
18 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
19 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
19 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
9 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
6 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
28 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
19 views

problem in inserting row to database

I have a custom table in database (named "wp_tasks") it has 5 fields. the problem is when i wanna insert the current time to this table it wouldn't, i checked for the first 4 fields, it works ...
0
votes
1answer
54 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
26 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
23 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
24 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
16 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
29 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
23 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
22 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
20 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
21 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
35 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
81 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
45 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
17 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
46 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
9 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
58 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
129 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
72 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
39 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
41 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 - ...
0
votes
0answers
127 views

SQL query to get all nav menu items and their titles/label

I want to get a list of all nav menu items displayed in a menu having id "19" in my search page to match against the search string. I would like to get names of menu items as displayed on frontend. I ...
0
votes
1answer
51 views

Create Array from data in the OPTIONS table

Good Day everyone, I'm trying to create an array from data in the Options table of wordpress. My data all start the same way plugin_order_ and then name of the field information. Is there a way to ...
0
votes
1answer
70 views

Protect custom form from SQL injection

I'm trying to understand how to protect my custom form from possible attacks. I send a data via a form, let's say userdata, then I read it: $userdata = $_POST['userdata'] I put it into an array to ...
2
votes
2answers
50 views

SQL to check how many sites a user is a member of

I have a multisite installation and I'm working on creating a reporting plugin. One of the things that I would like to do is show the number of sites a user is a member of. Right now, I'm using ...
0
votes
1answer
37 views

Help with SQL query, how to add taxonomie terms with value stored in options?

i need your help in making SQL What i have: custom post type ( company ) taxonomie ( category ) applyed to cpt ( and has ct section select field ) custom taxonomie ( section ) applyed to nothing ...
1
vote
1answer
50 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
2answers
52 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 ...
2
votes
1answer
116 views

SQL query to get adjacent posts from search query

I'm busy rewritting a custom function I have recently written to get adjacent posts according to a tag, category, custom taxonomy term, author or search value saved in the URL I'm using the structure ...
1
vote
0answers
63 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 ...
0
votes
0answers
12 views

What are the steps to migrating my blog to a new host?

I recently bought hosting service with Namecheap. I backed up my db from my previous host and now want to migrate everything. I was restoring the db with phpMyAdmin, uploading the sql file, but this ...
0
votes
1answer
50 views

WP Sql query multiple where clause

I'm trying to get the users that have registered after a specific time (this case $today) and who have the newsletter field true and the account false. This is what I have so far but the result is ...
1
vote
1answer
99 views

Add custom fields to search

I want to add a custom fields ("introduction" and "ensavoirplus") to search of Wordpress, but the SQL code is not exact. I don't understand if i do a mistake or if WP don't can do this. But my attempt ...
0
votes
0answers
42 views

How to merge 2 WordPress sites?

I have 2 WordPress sites, A and B. Each of them has users and posts. Now, I want to merge these sites. Points to be noted- A has 1000 users and 2000 posts. B has 500 users and 3000 posts. There are ...
0
votes
1answer
145 views

WPDB update row with != in where clause

I'm using wpdb to develop a plugin to add a custom form to wordpress. To update a row, I use an array and wpdb->update(). WP Class Reference says: My SQL code should be something like UPDATE ...
1
vote
0answers
36 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 = ...
0
votes
1answer
24 views

Creating a “forum” - showing last post or last commented post

thanks for reading! Im creating a forum just using categories and posts. I'd like (as most forums do) to show the last commented post or the last created post (which ever is newer) next to the ...
0
votes
1answer
40 views

Front end access to a SQL data repository - recommended way?

Building a general data repository, not necessarily related to WordPress elements. What is the recommended way of doing it: Using custom post types? or Building new SQL tables? Please elaborate. ...
0
votes
2answers
1k views

Insert Query not working in the form

Many people has asked the same question, I have read those things and mine is different, I am trying to insert some values inside the database from the form but it's not getting inserted I have a ...
0
votes
0answers
713 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 ...
0
votes
1answer
30 views

Debugging WordPress

Looking for advice on debugging sql queries. I find that plugins and themes are causing heavy queries and slowing performance. Any easy ways for doing this? Tools? Shortcuts? Thanks! Daniel