The wpdb class, accessed via the $wpdb global variable, is used to interact with the WordPress database
0
votes
1answer
174 views
Compare transient data with a meta box value
So I'm not sure what would be the best way to go about this in terms of best practices and optimization.
Scenario:
I have query that parses an external XML feed and stores the data using the ...
0
votes
1answer
569 views
Ajax future single post query doesn't work when NOT logged in
I am having a problem with an ajax request for a single post, when the user is not logged in. The post is a calendar date and is in the future. the query works fine if I am logged into wordpress but ...
0
votes
1answer
394 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
1answer
21 views
Get all sticky posts from one user through user ID
So I need to get number of sticky posts each user have and compare it to one variable. I managed to do this, but I am wondering is this the right way to do it.
//Retrive all sticky posts ID
...
0
votes
2answers
93 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
1answer
35 views
How-To: wpdb Insert Record With Date
I am writing a plugin where I need to pre-load some data in the custom tables that I create upon Activation. My inserts have run fine thus far until I attempt to insert a record with a DATE datatype. ...
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
1answer
48 views
$wpdb->insert Database Error Duplicate Entry Error Logging
Is there an equivalent to INSERT IGNORE in the wpdb class? As I'm fetching and inserting a twitter feed and the field in which I store the tweet ID is keyed UNIQUE, I am aware that duplicates are ...
0
votes
1answer
53 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
41 views
accessing wordpress serialized data outside wp
I've never worked with serialized data... I need a little help with how to load "text" widgets title and content in php script outside wordpress...
my script just connects to database (including ...
0
votes
1answer
88 views
Select From wpdb - Author/User Directory page
I am working on a wordpress site where I have created a directory page(authors.php) that lists all users and certain author meta.
It works fine however I am trying to figure out how to only show ...
0
votes
1answer
35 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 ...
0
votes
2answers
97 views
How do I create a single.php for a specific category?
I am trying to create a single.php file for a specific category on my site. Instead of loading the single.php file I want WP to return that category in a file called single-category-53.php (the actual ...
0
votes
1answer
113 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 = ...
0
votes
1answer
154 views
How to insert multiple postmeta values with one query?
I have a custom script/plugin I am using for myself that creates a post along with some postmeta information. Right now, I have multiple $wpdb->insert, but I would like to condense this down into ...
0
votes
2answers
138 views
How to pass NULL in where array for $wpdb->update
how to get results of a row with NULL element?
I have to update the row which contains only the post_id and the repeat value, 'start' and 'end' should be NULL
mysql table screenshot: ...
0
votes
2answers
77 views
$wpdb->prepare error after Wordpress update [duplicate]
Possible Duplicate:
$wpdb->prepare() warning in WordPress 3.5
Im facing with a error after updated Wordpress to 3.5, Im aware of error but I cant fix it.
This is code:
...
0
votes
2answers
92 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
2answers
40 views
wpdb result arrray inside an array
I am trying to run a database query as below:
$id = $_GET['id'];
$query = 'select * from ';
$query .= $wpdb->get_blog_prefix() . 'fxdescription ';
$query .= 'where id= '.$id;
$currency = ...
0
votes
1answer
238 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
211 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 ...
0
votes
1answer
182 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
112 views
Creating and Using Tables in the Wordpress Database
I plan on having over 2,000 pages per subject on my WordPress website and since each subject will require custom page types I would like to create tables for each subject in the WordPress Database. ...
0
votes
1answer
506 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
246 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 = ...
0
votes
1answer
85 views
Are there risks associated with using wp_options table using wpdb to update theme options
I am making a theme and it has so many options that need to be updated via jquery's ajax.Having looked at ways of updating wp_options via ajax,i have hypothesised that updating the wp_options table ...
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
196 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 ...
0
votes
1answer
103 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
396 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
299 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 ...
0
votes
1answer
166 views
wpdb->insert not inserting first variable
I have a strange error here. im trying to write to the wordpress db but $wpdb->insert does not write the variable first name.
Can any one spot the error in this code?
function ...
0
votes
2answers
854 views
Use have_posts() with array of post results retrieved by $wpdb->get_results
I don't know if I'm retarded, crazy or just plain genius or not, but I've decided to use tags as a way to link content site-wide (a big ol' many-to-many relationship website for archiving various ...
0
votes
1answer
93 views
how to translate countries output from wp database?
i have a list of countries in french stored in my database (wp_country). i use the code above to retrieve all the countries witth this ecohing echo '"' . $country['name_country'] . '",'; it outputs ...
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
218 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
1answer
578 views
$wpdb->num_rows doesn't work
I'm trying to perform some checks on custom fields before they are saved on a db. So I decided to use an add_filter as it does this between browser and db. Here is my code
function ...
0
votes
1answer
60 views
Insert data through a script directly in the db
is it possible to insert data through a script or HTML site into the wpdb and this will show up as normal article in the, the same as when I use the 'create new post' page?
Which tables are affected ...
0
votes
1answer
55 views
Linked pages from plugin on front can't see $wpdb
I obviously need more knowledge re this one.
From my plugin.
I have a custom main page which displays my custom db data table of a list of stores.
Each store has a "link" ie using a href eg.
<a ...
0
votes
2answers
203 views
Trouble inserting string containing quotations marks with wpdb in save_post hook
I'm having trouble with inserting a string which is containing quotation marks in wordpress via wpdb.
I've written a hook for save_post and trying to write the post_title in a table via wpdp->update.
...
0
votes
1answer
206 views
What's wrong with this wpdb query?
I want to select some tags with the same term_group, I tested it in phpadmin, the query get the correct result, but once add $wpdb flavor, it returns an empty array. Any advice?
$primary_tag_id = // ...
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 ...
0
votes
1answer
268 views
$wpdb->flush(); breaks the loop
I am using $wpdb->flush(); at the base of my page in an attempt to prevent the query executing multiple times due to caching however it seems that it isn't flushing the most recent query but the ...
0
votes
1answer
565 views
wpdb->get_var - count author posts, meta value
In an author.php template, i count the author post in a custom post type with $wpdb->get_var,
$post_author = $curauth->ID; //author id
$count = $wpdb->get_var( "SELECT COUNT(*) FROM ...
0
votes
1answer
256 views
$wpdb->get_var next var?
This is giving the same views value for each post how would I grab the next var for each post?
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<a href="<?php ...
0
votes
1answer
229 views
How can I change my meta_query to SQL wpdb query?
I want to extract post related to 3 meta_data fields called bed_value, bath_value, rob_value the variable data is $bedrooms, $bathrooms, &rob, I got some confused with join and like structure. The ...
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
870 views
How does $wpdb handle COUNT(*)
I understand how to do simple queries and display results using $wpdb. This is my process:
<?php $sql = 'select * from wp_votes;'; ?>
<?php $votes = $wpdb->get_results($sql); ?>
...
0
votes
1answer
761 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 ...
0
votes
1answer
2k views
wpdb->prepare and mysql UPDATE - how is it done?
Trying to set a 'removed' date time in a plugin query but I'm not sure how to use UPDATE SET with $wpdb->prepare.
Here's my query:
$cur_date = date('Y-m-d G:i:s');
$rows_affected = ...
