Tagged Questions
0
votes
1answer
24 views
Best practice to limit results in get_row()?
This is my query to check if a title exists (it's in a loop, therefore [$i]).
$wpdb->get_row("SELECT * FROM wp_posts WHERE post_title = '" . $titles_arr[$i] . "'", 'ARRAY_A');
Anyway, I would ...
0
votes
0answers
60 views
Custom query on Wordpress custom table
I am working with a custom table where some values will be inserted or updated if they already exists, I have checked and rechecked the syntax and it seems to be working fine, if I run the same query ...
0
votes
1answer
34 views
Mysql query and odd results
I've a query here :
$sql = "SELECT ID,post_title,post_content,post_date,post_type
FROM {$wpdb->posts}
WHERE post_content LIKE {$stuff}
AND post_status = 'publish'
AND post_type = ...
0
votes
1answer
36 views
Help with Related Posts Function
I'm trying to write a function that will grab all related posts according to the term of a taxonomy. I'm having trouble though trying to query multiple terms.
The way I am doing it right now is using ...
4
votes
1answer
97 views
Custom query to get post names beginning with a digit
I'm implementing an A-Z index for a custom post type. I've got my links printing out the page and the query working for the letters. However, the numbers are tripping me up because I don't want them ...
0
votes
1answer
62 views
How to check for empty and not a failure
I'm querying the postmeta table to see if a url has already been entered, using this statement (where $thisLink is the url I'm checking)
$mypostids = $wpdb->get_results("select * from ...
0
votes
2answers
93 views
Wordpress $wpdb no result
I have the following code in my functions.php
$code = 'EUR';
global $wpdb;
$query = 'SELECT * FROM ';
$query .= $wpdb->get_blog_prefix() . 'fxbase ';
$query .= 'WHERE code= '.$code;
$data = ...
0
votes
0answers
6 views
What would make a MySQL database create tables in a different collation other than its default? [duplicate]
Possible Duplicate:
Using wpdb to connect to a separate database
am adding tables to a Wordpress database on my localhost and it is changing my collation from utf8_general_ci to ...
1
vote
2answers
160 views
$wpdb: Counting posts corresponding to 3 terms in 3 different taxonomies
It's easier if I made an example:
I have a custom post type MYPOSTTYPE, with 3 taxonomies TAX_1, TAX_2 and TAX_3
If I have 3 terms: 'TERM_TAX_1' in TAX_1, 'TERM_TAX_2' in TAX_2, and 'TERM_TAX_3' in ...
0
votes
1answer
228 views
Get post featured image id with $wpdb
I'm not a sql expert, but with some help and copying from queries I've found on the web I got this working one that gets the 20 closest places (custom post type) to a specific latitude and longitude ...
1
vote
1answer
479 views
Get multiple custom field values in a $wpdb query [duplicate]
Possible Duplicate:
How to query posts based on lat-lng coordinate as post meta?
I want to create a $wpdb query that select the closest places (custom post type) near the current ...
0
votes
1answer
38 views
Nothing happens on Wordpress Update command
I made a function in Wordpress, which should update one field status to 0. But no changes are made to the database. I don't know what is the reason. Can someone please help.
I tried looking into ...
2
votes
1answer
253 views
Increment value (value = value+1) of $wpdb->update
This sql query
$wpdb->query("UPDATE log SET total=total+1 WHERE id='1')");
How do I turn it into $wpdb->update() statement?
Ex.
$wpdb->update('log', array('total'=>'total+1'), ...
1
vote
2answers
134 views
Join new table with SQL query
I created a plugin with a new table (wp_soundcloud) and I need to retrieve the data from that new table along with the post data.
Here is my query:
$querystr = "
SELECT $wpdb->posts.*,
...
0
votes
1answer
249 views
populate select options from extra mysql table data
hi guys i am trying to populate a select element with options from the data in one of my sql tables heres what i have so far:
<?
$SQL = "SELECT * FROM pt_country ORDER BY name";
$rs = ...
1
vote
1answer
145 views
How to split the a table in database?
Is there any option to split the tables in more tables in different databases? The problem is that my the wp_posts table is to big and it takes a lot of time to show in the Dashboards... (more than 20 ...
4
votes
1answer
175 views
find a random blogid across my multisite network that has at least one post published
I need to find a random blog across my multisite network that has at least one post published of a certain post_type, and return its blogid as a variable so I can use it in a switch_to_blog() call.
I ...
1
vote
0answers
106 views
Query most popular terms by taxonomy over 2 week period
I have written SQL for a query that pulls the most used taxonomy terms for selected taxonomies that are published, do not have a parent post are not in a comma separated list over the past two weeks ...
2
votes
2answers
326 views
Database slowdown after update to 3.4.1
I own a wordpress installation, and Updated to 3.4.1.
After the upgrade, I got a very strange slowdown to my wordpress.
After all, I used the
define('SAVEQUERIES', true);
in my wp-config.php with ...
0
votes
1answer
87 views
Different sql queries count indicator on the main page
I use w3_total_cache plugin. But i can`t understand what is going on sometimes. I have enabled database caching and debug info at the bottom. Sometimes on the main page 90-96 db queries, sometimes ...
3
votes
2answers
458 views
Can i use php sql functions instead of $wpdb?
New to wordpress and was wondering why in Wordpress API do they tell you to use functions such as prepare(),insert(),get_col(),get_row(), query(), etc. when technically i can use the built in PHP sql ...
0
votes
1answer
255 views
SQL query not working in alphabetical post title/content search
I have an ajax request using wp_ajax sending one variable named "q" what I want to do is after the script get's the request to look inside the db and fetch the title and id of the corresponding posts ...
0
votes
1answer
105 views
get_var is neither a string, integer, or array …?
$vote_count = $wpdb->get_var($wpdb->prepare("SELECT votes FROM wp_mytable WHERE product = %s AND
company = %s", $product, $company));
...
0
votes
1answer
397 views
PHP variables in mysql query
What is the consensus on how to insert variables in a MySQL query using the $wpdb->insert syntax: ($table, array($column=>$value),$format)?
I know this hasn't worked:
...
0
votes
1answer
301 views
Query the links Database
Hi I'm trying to convert from a "example" wp_list_table that displays an array of data on the same page, to a "real life" table the pulls data from the database. I have the code setup to where I just ...
1
vote
2answers
289 views
wpdb Custom Meta Data with 2 conditions
This is one of those problems that I've spent way too much time on, and there is probably a VERY simple solution that I am missing. Any help would be greatly appreciated.
I am trying to populate a ...
1
vote
2answers
235 views
Mysql query LIKE not working
I'm using this code.
$blog_list = $wpdb->get_results( "SELECT " . $extra . "blog_id, last_updated FROM " . $wpdb->blogs. " WHERE public = '1' AND archived = '0' AND mature = '0' AND spam = '0' ...
1
vote
3answers
928 views
Help With MySQL to WPDB Query Conversion
I have a problem. I've got a PHP script that tracks individual file downloads, and I'm looking for a way to display that number in individual posts. I've got a half-baked solution- a plain ol' MySQL ...
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 ...
0
votes
2answers
202 views
wpdb function insert doesn't work
It just won't insert anything, if I echo it, it will show everything fine, but it won't insert anything in database. The table name is correct. Code -
global $wpdb;
$meta2 = ...
0
votes
1answer
773 views
Wordpress database error: [Query was empty] - using $wpdb->prepare()
I have edited my question, I'm now getting the error about checking my MySQL settings. I changed the $sql_dvalues variable to an array with the values instead of comma spaced values and now it is ...
1
vote
1answer
327 views
MySQL Query To Select Post By Postmeta
I have two custom post types, type1 and type2. Type2 posts have a postmeta called postID that is the ID number of a post in type1. When showing type1 in single.php I want a mysql query that selects ...
1
vote
1answer
110 views
MySQL Rank & $wpdb
I need a rank column in my MySQL statement, for example:
SET @rank=0;
SELECT @rank:=@rank +1 as rank, player, points
FROM my_table
Is there a way to use the above with $wpdb? WordPress doesn't ...
0
votes
1answer
834 views
Wordpress $wpdb get posts from category and sort by custom meta
I have a custom post type of 'events' which has a meta key 'event_date'
Im using the following to retrieve those posts and arrange them by 'event_date'
global $wpdb;
$today = ...
0
votes
1answer
197 views
query for filtering published posts?
i need to filter count based on a date and post_status = 'publish', how to write a query to filter, as far as now i have filtered based on date, what is the query need to filter based published post.
...
0
votes
1answer
2k views
Should I use wpdb prepare?
I'm new to SQL and am wondering if I need to use wpdb->prepare for the following query to a table I've created
global $wpdb;
$tablename = $wpdb->prefix . "my_custom_table";
$sql = "SELECT * ...
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 ...
0
votes
2answers
538 views
Have working sql query… trying to adjust it to use $wpdb
So I have this code that queries a custom plugin generated table in the wp database. It works perfectly as is. But I'm trying to adjust it to use $wpdb instead of the $con function I have set up.
...
0
votes
1answer
395 views
Placing a widget with $wpdb query
I'm getting the feeling that adding Widgets via MySQL query is not as simple as I thought. I was under the impression all data is stored in the options table, but it seems like I was wrong.
Any idea ...
0
votes
2answers
731 views
Wordpress(wpdb class) and mysql stored procedures
$query = "CALL ..........";
$result = $wpdb->get_results($query);
print_r($results);
Is returning an empty array and $wpdb->query does not return anything, how do you run stored procedures from ...
14
votes
6answers
10k views
Using wpdb to connect to a separate database
I want to connect wpdb to another database. How do I create the instance and pass it the database name/username/password?
Thanks