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 ...
1
vote
2answers
27 views
How to write: $wpdb->update having WHERE NOT value pair in the array
I need to update all meta keys in the postmeta table that have a value other than 0, to the value of 0.
I tried this.. no love (though I cannot figure out why....):
$status = $wpdb->query("UPDATE ...
0
votes
1answer
17 views
Adding an orderby filter, casting postmeta with multiple keys
I am using this filter to sort my query by a date field stored as text (legacy data)
add_filter( 'posts_orderby', 'my_posts_orderby_date', 10, 2 );
function my_posts_orderby_date( $orderby, $query ) ...
0
votes
0answers
39 views
Retrieve post data via WPDB class
I'm trying to figure out doing a custom query using the $wpdb Object.
I have custom type posts, event_posts, that have meta data, images, as well as event dates which are input in the post with the ...
0
votes
2answers
97 views
$wpdb returns no results with SELECT query on custom post type, works on default post type
EDIT: Adding more background info.
I've coded a plugin that adds a meta box to the post page. When the post is published, the plugin will generate a random ID for the post, and insert the random ID ...
0
votes
0answers
44 views
get_query_var('paged') giving same result
I have a custom page, in that page i am using a custom select query for my search functionality.
The problem is pagination not working. I used $on_page= get_query_var('paged'); for pagination. When ...
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 ...
0
votes
0answers
59 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 ...
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
0answers
12 views
sequnce in enter words in wordpss search using query
I have a problem in creating advanced search with custom query and using $wpdb->get_results($query , OBJECT);
In Normal search in wordpress when we search xxx yyyy or search yyyy xxx we have same ...
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 ...
1
vote
0answers
62 views
Changing status of Published posts which have less Content to “Draft”
function draftpost(){
global $wpdb;
$prefix = $wpdb->prefix;
$wpdb->query("UPDATE ".$prefix."posts SET post_status='draft' WHERE LENGTH( post_content ) <500");
}
...
0
votes
1answer
240 views
wpdb update multiple row?
I need to change the meta value of all users at once. Seem there are no api for this,except using custom database query.
This is my code:
$matches = array('meta_key' => 'user_token');
$data = ...
0
votes
1answer
184 views
How to use wildcards in $wpdb queries using $wpdb->get_results & $wpdb->prepare?
I am attempting to make a custom search for BuddyPress groups.
Here is my method:
public function search_groups($string){
global $wpdb;
$results = $wpdb->get_results($wpdb->prepare(
...
0
votes
1answer
514 views
$wpdb query a post type within a specific taxonomy term while ordering posts by custom meta value?
I have a custom post type 'event', a custom meta field 'event_date' and a custom taxonomy 'locations'.
I want to query $wpdb to retrieve posts in this way
posts must be of the 'event' post type
...
0
votes
1answer
645 views
$wpdb->get_var not returning a result
I launched mysql and confirmed this query returns a result:
mysql> SELECT * FROM wp_posts WHERE post_parent = 68 AND post_type = 'attachment' AND post_name = 'side-logo-auto2' LIMIT 1;
1 row in ...
0
votes
2answers
1k views
Custom $wpdb Query for Custom Post Type by Category
I am using the following code to output a list of items in my 'documents' Custom Post type by Year and Month.
<ul>
<?php
$post_type = 'documents';
global $wpdb;
/**/
$years = ...
0
votes
2answers
197 views
Disable (or limit) queries when certain content (or data) is not needed (or showed)
Currently I am making a custom design for a site. The problem I'm seeing in Wordpress is about almost all data pulled out from the database.
While in certain pages - like front-page.php - it only ...
2
votes
1answer
1k views
WordPress Paginate $wpdb->get_results
Due to a complex multisite config, I have a query which combines the posts from two blogs and I would like to paginate the results. I am grateful for any help. I have posted my query.
...
0
votes
1answer
105 views
How to reference same column name but different table in custom db query
I use wpdb to connect to a custom db, then I use the following query:
$my_row = $wpdb_c->get_results("SELECT Employee.Name, Area.Name, Area.Region FROM Area INNER JOIN Employee ON Area.ID = ...
0
votes
2answers
54 views
plugin code is pulling information from database in one instance and not in other. What is wrong?
In my plugin code, I am pulling the table id from two tables. The id is being pulled from one table but not from the other and I get errors in both instances. The queries work on mysql when I use ...
0
votes
3answers
180 views
Retrieving custom field array value through db query
I'm trying to query the database for posts based on multiple custom fields. This is easy enough with the code below if values are simple:
$querydetails = "
SELECT wposts.*
FROM ...
0
votes
1answer
313 views
paginate_links on custom query in admin - 'sufficient permissions' error
I have created a page in my admin with this custom query:
$rows = $wpdb->get_results("SELECT * FROM ej_feedback ORDER BY createdtime ASC");
I have made it successfully paginate as required in ...
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 ...
1
vote
1answer
474 views
Custom Query num_rows returns wrong amount
So I have a custom query that fetches all posts in a given category. I am trying to get the number of rows returned but it is giving me the wrong number.
Instead of 11, I am getting 14. Does anyone ...
1
vote
1answer
668 views
$wpdb doesn't appear to work on page inside of a plugin
I have a plugin folder foobar.
Inside this plugin I have a page called foobar.php. Inside this page I have
global $wpdb;
$orderby = (!empty($_REQUEST['orderby'])) ? $_REQUEST['orderby'] : ...
0
votes
1answer
522 views
Formatting a date/time returned from a custom $wpdb query
I'm definitely a rookie WordPress/PHP developer, so please forgive ignorance :-)
Q: How do I format a date/time returned from a custom query against $wpdb?
Here's the scenario: I'm trying to write a ...
0
votes
1answer
79 views
db query for retrieving comments without any reply
what is a query for selecting a list of comment id's that have not had a reply yet so I can use it to iterate though each comment id and echo out the post it is on and the excerpt of the comment along ...
1
vote
1answer
156 views
Most effective use of DB querys
I've got a custom database table with lots of data that I'd like to query several times from a custom template file I've built. Say the db table looks like this:
id name city zip
23 ...
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 ...
0
votes
2answers
1k views
Use mysql_query instead of $wpdb query
I have a custom table inside my wordpress database called test.
What if i query this table using mysql_query() instead of using for example $wpdb->get_results()
Will this affect my performance?
Ty ...
1
vote
2answers
1k views
mysql query two database tables, users and usermeta and sort by custom meta int value
I am trying to get an array of site users sorted by a custom meta value (an int).
I can query the users just fine and get them back to use in a foreach. I currently have the query results come back ...
1
vote
4answers
1k views
Export wordpress table to excel
I have created PHP scripts before to export a database table to .xls format like this:
$select = "SELECT * FROM tracking";
$export = mysql_query ( $select ) or die ( "Sql error : " . mysql_error( ) ...
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 ...