Tagged Questions
0
votes
1answer
22 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 ...
1
vote
1answer
20 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
1answer
54 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
1answer
64 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
48 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 );
...
0
votes
1answer
25 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
0answers
34 views
Not Creating New Database Table [closed]
I've successfully created tables with previous plugins I've messed around with, but I can't seem to figure out exactly what's wrong with this. Hopefully it's an easy fix.
//CREATE ...
4
votes
1answer
67 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
115 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
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 ...
1
vote
1answer
72 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 ...
2
votes
2answers
275 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
600 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 ...
2
votes
1answer
400 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
1k 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] ...
0
votes
2answers
219 views
Fetching review value using wpdb class
I'm generating an XML file using PHP for a website where they review tech products. In the XML file, I have to display the rating of products. For rating purposes, I'm using GD Star Rating plugin.
...
0
votes
2answers
148 views
Get comments after specific date
I don't think this is a parameter in get_comments( $args ); so I'm using a SQL statement. First I obtain a comment date from a separate table I created. Afterwards, I want to retrieve all comments ...
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
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
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
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 ...
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 ...
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 ...