The sql tag has no wiki summary.
15
votes
5answers
18k 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
11
votes
3answers
311 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 ...
6
votes
2answers
7k 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',
...
5
votes
6answers
16k 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 ...
4
votes
1answer
2k 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 ...
4
votes
2answers
2k 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
1answer
410 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
68 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
2answers
607 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
153 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
1answer
159 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
127 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
443 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
667 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
77 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
3k 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 ...
2
votes
3answers
3k 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
277 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 = ...
2
votes
2answers
1k 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
44 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
87 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
402 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
211 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
2k 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
2answers
443 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
2k 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
51 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
2answers
152 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
1answer
554 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
1answer
359 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
1answer
164 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
227 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
2answers
128 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
164 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
2answers
503 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 ...
1
vote
4answers
3k 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 ...
1
vote
1answer
238 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
135 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
999 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
3answers
162 views
Retrieving a Value from a wp-database
why my sql statement is not returning any value.. is this wrong?
<?php
global $wpdb;
$result = $wpdb->get_results($wpdb->prepare("SELECT * FROM ...
1
vote
1answer
42 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 ...
1
vote
1answer
27 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 ...
1
vote
1answer
85 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 ...
1
vote
1answer
73 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 ...
1
vote
1answer
1k views
Add Admin User via SQL
I gave my client the admin account to his wordpress install and I forgot to add an administrator user for myself. Now, I can no longer access the admin panel because they have changed their password. ...
1
vote
1answer
348 views
Preferred Method of debugging a wordpress SQL calls?
What is your preferred method of debugging Wordpress Applications when writing custom behind-the-scenes SQL calls, etc. ?
Coming from a Rails background, I usually tail a log file that displays not ...
1
vote
1answer
954 views
Order query by meta_value with multiple custom fields
I would like to get ordered all my posts with multiple cutom fields (WordPress 3).
Exemple, I've 2 custom couple meta_key/meta_value :
" order_submenuexpositions / numeric "
" ...
1
vote
1answer
369 views
Best Way to Merge a Dev and Live Site to Become a Staging Site?
I have two Wordpress installs, both with a little bit of different data.
I have a LIVE site and I have a DEV Site. I need to merge the content of these two databases together to make a STAGING Site.
...
