The sql tag has no wiki summary.
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 ...
0
votes
1answer
41 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 ...
0
votes
1answer
157 views
SQL query add only posts with custom field to array
I have this SQL query which is building an array of wordpress posts...
$query = "select $wpdb->posts.* from $wpdb->posts,$wpdb->terms,$wpdb->term_taxonomy,$wpdb->term_relationships ...
1
vote
1answer
86 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
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 ...
0
votes
1answer
116 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
174 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
48 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
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, ...
1
vote
2answers
37 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 ...
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 ...
0
votes
1answer
110 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 = ...
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 <= ...
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:
...
0
votes
1answer
2k views
Overriding default calendar to show posts from a category
I'm trying to modify the default WP calendar (get_calendar()) so that it shows posts from a specific category and then use that as a shortcode.
Here's what I've done:
Copied across the ...
1
vote
1answer
74 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
83 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
74 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
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 ...
4
votes
1answer
411 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 ...
2
votes
2answers
278 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
42 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 ...
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 ...
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
...
0
votes
2answers
51 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
188 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
239 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
0answers
132 views
Retrieve/get current image from Nextgen gallery db
I thought that I can do it using the database where the idea was to get the image from the ngg_gallery_pictures table, where the browser URL is equal to URL of the image in the table.
Then I will get ...
0
votes
1answer
241 views
SQL Query members by profile fields Buddypress
i am trying to add a profile based search option into my existing plugin. my plugin already search members by distance within a certain radius and i want to add the option to filter results by profile ...
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 ...
0
votes
1answer
56 views
List recent 25 blogs across the network
I need to list recent 25 blogs in the network with their title. How to edit this code ?
$bcount = get_blog_count();
global $wpdb;
$blogs = $wpdb->get_results($wpdb->prepare("SELECT * FROM ...
15
votes
5answers
19k 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
1
vote
1answer
158 views
Location-Based Pages displaying results near customer
I'm creating a website where the customer will enter their postal code and the pages (with a distance selected of 5, 10, 20 miles) will display on either a Google map or Bing map. The page results ...
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 ...
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 ...
0
votes
1answer
190 views
Show array of meta_value in Edit Post Coloum
what I'm trying to do is add a new coloumn to Edit post page (done) and in that coloumn show data taken from a set of custom fields (partially done).
This is my code (I use it as a plugin so it ...
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 ...
0
votes
2answers
312 views
Display latest post from Wordpress Featured Category that is also in X,Y,or Z categories
I want to display the latest post from a "featured" category (id=1) that may also be in either X category, Y category, or Z category (id=2,3,4 respectively). Note, there are other posts in categories ...
2
votes
1answer
404 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 ...
0
votes
1answer
397 views
latency problems with wordpress install (from SQL import)
I develop wordpress sites for a living, and today I am experiencing something that I haven't yet come across: Extremely slow load times / latency problems. You can view the site here: ...
0
votes
1answer
192 views
Alter SQL query to return posts with unique custom field value, no duplicate values
I currently have a list of posts with the custom field "Name," with several posts having the same value for "Name."
I would like to retrieve a list of posts that all have unique values for "Name." ...
0
votes
3answers
542 views
How do I add indexes to Wordpress Database?
I got a message from Hostgator about my account being suspended because of the load it put on their servers. This is about the fifth time this has happened. I am on a shared server.
And they said it ...
-1
votes
1answer
61 views
Adding profile data to database
I added a custom field to my wordpress user profile page that asks a user what their favorite browser is. I have the field on the profile.php page, but how can I get this field into my sql database?
...
0
votes
1answer
178 views
How to get from sql query page id and retrieve it url and title
Conditions:
Page have template, for example: /* Template name: News */
Explaining:
We have many pages, and one page with assigned template (/* Template name: News */).
I want on main page ...
1
vote
1answer
77 views
Get the timout value of a saved transient?
Does anyone know if there is a Wordpress function to get the timeout value of a saved transient? I am using a transient with a 5 minute timeout to cache data from a web API call locally. Between ...
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 = ...
0
votes
1answer
159 views
Remove password protection from all posts
So I messed up my blog (QBobble). I had an SQL backup, fortunately, so I reinstalled Wordpress, and imported my SQL database.
Unfortunately, it password protected all of my posts. I know that I can ...
2
votes
2answers
212 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 ...
0
votes
1answer
37 views
How to migrate a database from a server to another
I try the export method of phpmyadmin, but the user is exported with the data... so there is no way to re import it into another database without error message.
The old user is name : ...
0
votes
1answer
66 views
Proper approach to moving complete site from one domain to another AND preserve widgets
I consider myself fairly versed in this matter, however I've recently had a rash of issues when moving sites. I am able to successfully move the site, edit wp-config.php, move the database, etc.
...