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
1answer
305 views

Export all posts to import as product items

Up until now, my client has been using WordPress posts as his way to display his products. I now need to export all these posts into a CSV format so that I can format the CSV file and import it back ...
2
votes
1answer
100 views

Filter WordPress posts by between parameter

How to filter WordPress posts by a taxonomy and between parameter? Consider a mobile website with "memory size" taxonomy, I need to show posts that have more than 256 mb memory and less than 768 mb. ...
1
vote
1answer
147 views

How do i export the HTML from text widgets?

I placed HTML in several text widgets which where lost after i deleted all inactive widgets and changed themes but i have found the data in the tables. The only problem, its mixed in with all this ...
0
votes
0answers
81 views

Heavy SQL queries

I have got rid of one of SQL problems but the story isn't over. Now hoster has detected another problematic SQL query and again threatens to disable the account. Can anyone advise on what's going on ...
2
votes
2answers
739 views

How to properly sanitize strings without $wpdb->prepare?

I'm working on an advanced search (which uses custom sql queries), and the query string is formed using variables. For example, if the person checks some options, only those conditions get added to ...
0
votes
0answers
315 views

Install WordPress with SQL database

I am very new to WordPress. I didn't even know it existed until I had to do it for my work. So I started in with a WAMP server with WordPress. That worked fine until we needed multiple sites with ...
0
votes
1answer
70 views

How do I query for posts by custom meta and those that have been stickied?

I realize how clumsy and inefficient this query is but SQL is not my strong point. I use the following query to pull the latest 8 events from a custom post type called Event Posts. However, I also ...
0
votes
0answers
121 views

Special Query: Title, Terms, Content - %LIKE%

I'm working on a them theme that is search-heavy, and my users are putting huge priority on an improved search function. I think I will have to use a special direct query to search these things: ...
1
vote
1answer
120 views

wpdb query problem to access previous 3 days posts

I am trying to get all published posts titles by author id 2 most recent by post date for the last days. Here is my query: "SELECT post_title FROM $wpdb->posts WHERE post_status = 'publish' AND ...
8
votes
2answers
15k 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', ...
0
votes
1answer
224 views

Custom SQL query ORDER BY term_order

I have custom taxonomy that list terms under "series" that contain posts that are also present in terms under "media_type" and where media_type is term_id 16. I want to order the list by the ...
0
votes
0answers
177 views

Convert date format in meta

I have been storing date format in meta key/value. I have been storing in this format (mm/dd/YYYY) now I need to convert that into (YYYYMMDD) SO I can run a date match in query. Please advice how can ...
0
votes
2answers
85 views

Query posts based on parents attribute

This is the scenario: I have multiple pages that all have a custom field named "Location" Those pages all have child-pages with the custom field of "size_m2". What I want is to do a normal meta_query ...
1
vote
1answer
587 views

Select from wp_post and multiple meta_value from wp_postmeta

My lack of SQL skills has stopped me in my tracks here. I'm trying to select post_id, post_title and two postmeta values - the first has the meta_key of 'search_country' and the second a meta_key of ...
0
votes
2answers
281 views

Fetching review value using wpdb class

I'm generating an XML file using PHP for a website where they review tech products. In the XML file, I have to display the rating of products. For rating purposes, I'm using GD Star Rating plugin. ...
0
votes
2answers
139 views

Really simple query giving error in SQL syntax

I'm sure this is a simple oversight but I cannot seem to narrow it down: global $wpdb; $tablename = $wpdb->prefix . "icrm_folders"; $sql = $wpdb->prepare( "SELECT * FROM %s", $tablename ); ...
0
votes
2answers
397 views

How to update Wordpress custom SQL Select query for custom taxonomies so that syntax is correct?

I have a Wordpress website that written by third party web developer for version 2.9 before custom taxonomies were fully implemented. We have since upgraded to latest wordpress version 3.5.x. There ...
1
vote
0answers
82 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 ...
0
votes
1answer
57 views

Custom $wpdb returns unexpected time based results

I am using the $wpdb class to do a custom SQL query but I am getting weird results. Basically this is what my SQL query is supposed to do Retrieve the titles of post_types 'question' only if they ...
0
votes
2answers
78 views

Create a new page for each form selection

I have a got custom page template which displays a drop down box that has list of countries.A user selects the box and clicks sumbit.Page then then displays the relevant details for that country .IT ...
1
vote
1answer
43 views

Fetch all Posts where logged in user has commented

I'm not good at sql queries so the question is: How do I list all the Posts where logged in user has left the comment? I guess it's kinda obvious that redundancy is unwanted in case user posted ...
2
votes
4answers
6k 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
2answers
154 views

Assign a list of categories with a parent category

I imported hundreds of locations and other categories. Now I have a list of locations in categories to which I would like to assign the "Location" category as its parent. I have tried sql but the ...
0
votes
1answer
184 views

Using color schemes with Color Picker

What I'm doing User interface to change website colors - User can change colors individually (like menu color, footer color, content color), or use color scheme that will change all colors (values ...
0
votes
1answer
75 views

learn to run wpdb class

I want to learn how to run commands through WP rather than SQL commands I have a SQL command: SELECT post_id, (select meta_value from wp_postmeta where meta_key = a 'geo_latitude' AND x.post_id = ...
0
votes
1answer
90 views

Print page content with formatting when doing custom SQL query

I guess there's a simple solution for this but couldn't find any. I'm trying to fetch 3 pages and show them on footer. The problem is that every page is shown as text without formatting which means ...
1
vote
1answer
66 views

Wordpress Custom post query sorting does not work

I created a custom WP query to collect products that have 3 different taxonomy values in them and sorted them by price using the following: $my_products = new WP_Query( array( ...
0
votes
2answers
1k views

SQL query to get posts from multiple categories but not in a category

I need to get the last posts' ID and the post_tile within categories 1 and 2, and exclude those within category 3. It must be SQL, because if I use WP_Query it retrieves too much info and I only need ...
0
votes
2answers
919 views

Error establishing a database connection After Copy localhost wordpress site (with site url directly to hosting server's url before copy)

I have a localhost site that I heard I can migrate the site by just copy and paste the whole site from local to host if I changed WordPress Address (URL) and Site Address (URL) to my current hosted ...
2
votes
1answer
81 views

What is the easiest way to implement cascading database upgrade for my plugin?

Lets assume following situation: I develop a plugin. The plugin requires custom database table to store some kind of information. From month to month I release new versions of my plugin. Different ...
0
votes
1answer
51 views

finding out the top 5 source ( source is a custom taxonomy ), in a given category

The client I'm working with have thousands of articles and media ( audio/video ) files. To WordPress, all are posted by Author ID 1, which we named as STAFF. All the content though in reality has ...
1
vote
1answer
323 views

Recommended way to drop a pending query (in pre_get_posts)?

It looks like an e-commerce plugin's core query will be of no use to me in one particular template so I would like to discard it completely in favor of my own WP_Query loops in the template. It's not ...
4
votes
1answer
217 views

prepare() not working

When I do this: $transients = $wpdb->get_col( " SELECT option_name FROM $wpdb->options WHERE option_name LIKE '_transient_wb_tt_%' " ); It works ...
0
votes
1answer
337 views

Wordpress SQL JOIN query

Hi Im trying to run 2 querys in the same query call. // send the query global $wpdb; $commentQ = "SELECT * FROM $wpdb->comments " . $whereClause . $orderBy; $comments = ...
1
vote
2answers
647 views

wpdb->prepare function remove single quote for %s in SQL statment

I am using the below wpdb->prepare function in a sql statement. I am passing in several variables some field names and some values. When I try to use the %s for the field name it puts single quotes ...
0
votes
2answers
78 views

How to delete ALL comments from certain category in Wordpress database?

I'm trying to delete all comments from posts in a certain category in a Wordpress database. The Wordpress database is rather complicated so this must be probably some join of wp_posts, wp_comments ...
3
votes
2answers
711 views

Display only certain posts based on visitor's country?

Is it theoretically possible to have the following feature? Each post has a country code. When a visitor comes in, the system will determine the visitor's country code. Then when the page renders, ...
1
vote
2answers
98 views

How do you use prepare when asking for a list of id's

I'm looking to get a number of records back from the database given a list of numbers and was wondering how I would use $wpdb->prepare to do this (to take advantage of the sanitising vs SQL injection ...
6
votes
6answers
32k 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
319 views

pull data from a remote wordpress database

I am trying to pull some data from a remote wordpress database. Here is the code I have: $server = "my server code"; $user = "my username"; $password = "my password"; $db = "mydb"; $con = ...
3
votes
1answer
163 views

How should I intercept the main query and inject custom join / order by / group by criteria

I have a CPT that is a member of two separate taxonomies. On the taxonomy archive page for one of the taxonomies, I need to further group and sort on the second taxonomy like so: ...
1
vote
1answer
115 views

Modify the structure of data returned by $wpdb

Modify the structure of multidimensional array outputed by SQL via $wpdb The output that I need from $wpdb is easily achievable by running multiple queries within foreach. However, I am trying to ...
0
votes
1answer
146 views

Export / import Wordpress database

Is there a proper way of exporting and importing a big WordPress MySQL database to a new database? When I tried to do that in the standard way I run into 2 issues: All widgets disappeared and I had ...
4
votes
3answers
6k views

How do you properly prepare a %LIKE% SQL statement?

I'd like to use a LIKE %text% statement while still using the WordPress $wpdb class to sanitize and prepare input. SELECT column_1 from `prefix_my_table` WHERE column_2 LIKE '%something%'; I've ...
4
votes
1answer
1k views

Export WordPress Posts and Meta Information in CSV format

I need to export all WordPress Posts and related Meta information using an SQL query. I've managed to export just the Posts but realised that the Meta information is in another table. Could someone ...
3
votes
2answers
797 views

Display data from a non wordpress database on a page template

I am using a sql query to access information to display on a wordpress page by adding the below code to a page template. I know the query works as I've tested it in phpmyadmin. $rows = ...
0
votes
1answer
54 views

Return number of items in a table with post id

I am trying to return the number of reviews for a given page id, I have this so far... <?php global $wpdb; $countreviews = $wpdb->get_var($wpdb->prepare("SELECT COUNT(ID) FROM ...
13
votes
3answers
407 views

What are the common security flaws I need to look for? [closed]

As a wannabe WP plugin developper, what are the main security flaws/holes I should look for? I'm about to create a new plugin with a configuration panel (ie input fields and stuff). What should I be ...
2
votes
1answer
134 views

Sql syntax error

Sometimes in my error log i have this error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 ...
0
votes
2answers
68 views

Query is not work

I use this codes in my functions.php to track post views. /* Functions to track Post Views*/ function getPostViews($postID){ $count_key = 'post_views'; $count = get_post_meta($postID, $count_key, ...