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)

23
votes
5answers
44k views

How to display sql query that ran in query?

I have come across a function before that displayed the exact SQL code that was used in a loop for example, but can't remember. Can anybody tell me that function? Cheers
13
votes
3answers
413 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 ...
9
votes
2answers
16k 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', ...
6
votes
6answers
33k 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 ...
6
votes
1answer
3k views

Making my plugin multi-site compatible

I want my plugin to be installed on each blog and create database tables per blog. I have this code: register_activation_hook( __FILE__, 'install1' ); function install1() { global $wpdb; if ...
5
votes
2answers
3k views

How to correctly call custom field dates into a posts_where filter using SQL statements

Currently I have the loop listing posts between two dates using the posts_where filter: function filter_where( $where = '' ) { $where .= " AND post_date >= '2000-01-01' AND post_date <= ...
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 ...
4
votes
1answer
243 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 ...
3
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 ...
3
votes
3answers
2k views

SELECT max(meta_value) FROM wp_postmeta WHERE meta_key='price'… stops working when value is over 999

Overview: I am not trying to return a post. I simply want the single highest value for a particular meta_value across all posts... just the value itself. Details: I have added a custom meta_key ...
3
votes
2answers
822 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 = ...
3
votes
2answers
429 views

Sharing database for collaborative development

Is there a straightforward way to share/sync multiple WP instances with a single database? I work collaboratively with several developers on custom themed sites. We use git to keep our files in order ...
3
votes
2answers
3k views

Retrieving custom fields with $wpdb->get_results

I'm trying to use $wpdb->get_results to retrieve an array of all posts including custom fields. I can retrieve the meta_key and meta_value columns like this: [meta_key] => state [meta_value] ...
3
votes
1answer
191 views

How to make an activities stream mixing posts and comments?

What I'm currently trying to make is an activities stream wich list : The posts, the comments, both mixed between them and ordered by date. My idea is to make two queries, but i don't know how to ...
3
votes
1answer
167 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: ...
3
votes
2answers
730 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, ...
3
votes
1answer
967 views

Is it possible to wrap Geo Location search around WP_Query?

I'll just like to add that I have a current working solution in place and works well but I'm looking for ideas of being able to do it better or cleaner if possible. We have hundreds of properties in ...
2
votes
2answers
797 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 ...
2
votes
3answers
5k views

Pagination with custom SQL query

I have my own SQL string to select Custom Post Type posts with specific WHERE clause. I've used the offset and limit to return appropriate posts depending on a page being displayed. That's working ...
2
votes
2answers
2k views

SQL query to extract only the “current” wp_posts?

The wp_posts table seems to retain all revisions of the same, ok very similar but presumably different, posts/pages/whatever. I'm somewhat conversant with SQL but not WordPress. I need to extract ...
2
votes
2answers
2k views

How to set up default values for a plugin?

What is the best way to go about setting up default values for a plugin? Should I just insert those values into the wp_options table? AND...if that's the best way to go about it, I have another ...
2
votes
2answers
167 views

How can I get a list of plugins and which blogs are using them?

I'm about to upgrade my Wordpress MU installation to wordpress 3 Before I update, I want to find out which blogs use which plugins. I don't see a way to do that in the UI, is there? What about a ...
2
votes
2answers
2k views

Alter query on edit.php

What's the best way to alter the query being run on the Posts Edit screen (edit.php)? The current method I'm using is by passing an argument to the global $wp_query like so: $wp_query->query( ...
2
votes
1answer
101 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. ...
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 ...
2
votes
1answer
861 views

get_results on large datasets

I am experimenting some very disturbing problem using a custom SQL query. I have a custom MySQL table called trading_datas having 165 lines for 4,4Mo. One field datas of my table is a big serialized ...
2
votes
2answers
377 views

Moving database with phpMyAdmin

I have a remote (website) version of a wordpress site and it's got more recent information than my local (computer) version. I would like to move the data over to my local using phpMyAdmin, what is ...
2
votes
2answers
4k views

What's the easiest way to duplicate an entire navigation menu?

What's the easiest way to duplicate an entire navigation menu? I don't care if it involves SQL commands or whatnot. I just have some really big menus that I'd like to duplicate. Didn't see a plugin to ...
2
votes
2answers
2k views

Import old SQL dump into new Wordpress version

I'm trying to restore a Wordpress blog from a backup. Unfortunately, all I have is an SQL dump of the database as generated by phpMyAdmin. The dump was created when the blog was running Wordpress ...
2
votes
2answers
2k views

Improving WP_Query performance for multiple taxonomies

I have a site with several custom taxonomies, and have found that one of the slowest parts of the site is attempting to query with an OR across several of these at once. I'm using a WP_Query like so: ...
2
votes
1answer
754 views

orphaned taxonomy terms remove by sql query

I have 3 custom post types each of these CPT's have posts that are set to auto delete via a given time scale by cron jobs, thing is when they are deleted it leaves behind orphaned taxonomy terms in ...
2
votes
2answers
648 views

Use Cron to modify posts via sql

Hi to all I need to run this twice a day: UPDATE wp_posts SET post_content = REPLACE ( post_content, '[img]', '<img src="' ); UPDATE wp_posts SET post_content = REPLACE ( post_content, '[IMG]', ...
2
votes
2answers
3k views

Query between two meta values?

How do I limit the query by two custom meta fields, a start date and an end date? This is what my data looks like: meta_key | meta_value | ------------------------| start_date | 20100131 | //Jan ...
2
votes
1answer
82 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 ...
2
votes
1answer
292 views

Bulk add tag (or any sort of label) to posts who have custom excerpt

The situation is the following: The blog as of now has 2200+ posts. In the beginning (2007/2008) I was using manual excerpts where I would put an image and a little bit of text. The manual excerpt ...
2
votes
1answer
374 views

get posts and postmetas in assoc array

how do I get all posts and postmetas in an associative array? $allposts = $wpdb->get_results(" SELECT $wpdb->posts.post_title, $wpdb->postmeta.meta_key FROM $wpdb->posts JOIN ...
2
votes
2answers
256 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 ...
2
votes
1answer
240 views

Multipart/formatted MySQL query problem

I'm creating a plugin and I want to automate the creation of a MySQL Trigger on a table. The problem seems to be that $wpdb->query doesn't appear to accept either multipart statements and/or formatted ...
2
votes
1answer
266 views

Querying Email Addresses for a List of Users with Same Last Name?

I have a site with many users and many of them have the same last name. I want to get the emails of all the users with the same last name (IE: Smith) that has a post related to a particular taxonomy ...
2
votes
1answer
57 views

How to update records using $wpdb?

I am migrating non-wp database to Wordpress (for the first time in my life, and hopefully the last). As both new and old websites are multilingual, one of the tasks for me is to connect the articles ...
2
votes
2answers
930 views

How to add SQL file with PHP to WordPress database [closed]

I have SQL file with US zip codes (over 41000 lines of code). I want make a plugin that inserts this SQL file into WP database so user can do a search by zip codes. I want to insert SQL with PHP ...
2
votes
2answers
219 views

Extending WP_Query — Optimise SQL query

I'm storing posts, a user follows in a custom table that has the columns id, post_id and user_id. To fetch posts that a user follows I have extended the WP_Query as follows: class ...
1
vote
2answers
454 views

WPDB Insert or if exists Update

I'm not crazy familiar with WPDB or SQL in general but I have a custom table for my project and I'm trying to assign some metadata to it. What I'd "like" to happen is if a row exists, update it and if ...
1
vote
2answers
49 views

Query that joins the postmeta table twice

I believe what I'm trying to do is too complex for the standard meta_query parameter in get_posts, so I'm trying to use a custom SQL query to do the following: I have a game custom post that has ...
1
vote
1answer
731 views

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

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 ...
1
vote
1answer
160 views

$wpdb get_var issue

I've been at this for while, but can't figure out why the below isn't working. I have my date saved as a 'MM/DD/YYYY' string. global $wpdb; $new_day = $day->format("m/d/Y"); $qty = ...
1
vote
2answers
2k views

Export entries and multiple custom field meta to .csv?

First time poster. I'm trying to export a bunch of custom posts out to a csv file so I can easily import them into a new database. I've ran the native export to xml, but it's not the correct format I ...
1
vote
2answers
1k views

How to rename a custom field?

I have 3000 posts with that custom field name 'refer' and i need to change it to 'ref' for theme needs, instead of doing it manually i need a query or technique to change them all. Question 1 I am ...
1
vote
1answer
94 views

posts_where Fails with More than One Custom Field in Query

Querying either of the 2 fields individually gives the expected result (posts are displayed). But, when both fields are included in the query (ex = 'foo' and 'bar' shown in below example), then no ...