Tagged Questions

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
0answers
261 views

Get posts under a category with SQL

How can I retrieve posts under a category with plain SQL with out using WordPress native api's like get_pages? My Wordpress table wp_terms contains a term named Restaurants. I want to list the post ...
0
votes
2answers
76 views

How can I get all author written content?

I have a site that needs two different tabs: 1. all author written content (Posts, comments, CTP) 2. all author followed content (categories, taxonomies, other users content) For the first all I ...
2
votes
1answer
105 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
154 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
82 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
956 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
374 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
84 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
1answer
56 views

Advanced search: roles and multiple taxonomies

I have a site with custom roles, and custom taxonomies. I'm making the advanced search, where custom posts can be filtered by roles and taxonomies. To accomplish this, I'm using my own custom SQL ...
1
vote
1answer
127 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 ...
0
votes
0answers
127 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: ...
0
votes
1answer
272 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
2answers
894 views

Woocommerce: Grab total revenue of a product over all orders

I need to display the total revenue of all orders for my products depending on if the logged-in user is the author of the product or not. I can't use the Quantity field as a multiplier either because ...
0
votes
0answers
240 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
87 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
868 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
163 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 ); ...
1
vote
0answers
88 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
2answers
465 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 ...
0
votes
1answer
63 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
88 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
44 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 ...
0
votes
1answer
190 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
77 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
104 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
68 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
2k 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
1k 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
88 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
377 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
301 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
441 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
770 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
81 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 ...
1
vote
2answers
121 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 ...
0
votes
1answer
396 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 = ...
1
vote
1answer
131 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
159 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 ...
0
votes
1answer
335 views

Bulk move (or copy) from a custom field to the post content?

I need to move (or copy) the contents of a custom field into the main post body, replacing any existing content. I need to do this for a few hundred posts...Is there a quick way of doing this? I can ...
2
votes
2answers
270 views

What is an efficient way to query based on post_meta?

The problem I am having is when I allow users to filter posts it overpowers the database and things run extremely slow. I am unsure what the best way to query posts using meta values is. My site has a ...
4
votes
1answer
2k 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
907 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
56 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 ...
0
votes
1answer
335 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 ...
-1
votes
1answer
382 views

SQL query to return categories and category parents

I have some categories which are not correctly defined. I.e. their parents are messed up. How can I select with SQL all categories and their parents?
2
votes
1answer
136 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
70 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, ...
0
votes
3answers
449 views

Migrated to Namecheap, now Trouble with Database & wp-config [closed]

I have been using a free web host while I set up my WP site. Now that it's all done I went and bought hosting from Namecheap. I uploaded the site and WordPress and everything seems to look fine, but ...
1
vote
1answer
871 views

WPML tables not deleted when removing multisite subsite, need help clearing up my sql-file! [closed]

I´m building a WP Multisite for a client that wants a multilingual site. Before choosing WP Multisite, I bought and tried out WPML. However that plugin didn't fit for the job so I deleted it and got a ...