The wpdb class, accessed via the $wpdb global variable, is used to interact with the WordPress database
1
vote
1answer
158 views
Converting the_content string to an array?
I have created a custom taxonomy, this taxonomy is dedicated to image attachments, when I upload my images $post->post_content returns a string like:
'[caption id="attachment_98" align="alignnone" ...
0
votes
1answer
61 views
Compare string with post id in wpdb and do stuff when match is found
I'm looking for some help tying in with the wpdb to compare and change certain values. I'm very novice with mysql handling so I really appreciate any help on this matter!
What I want to do is to go ...
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
130 views
Wordpress choose wrong database
I have 2 databases. When I include the database connection (with a include('filename.php');) wordpress acts really strange.
I can't login, the wordpress username and password is right but it tries to ...
2
votes
2answers
276 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 = ...
1
vote
0answers
29 views
Code only works every other time its run
This code below works fine as long as I leave the $wpdb query commented out.
However, I'm trying to clear the current settings before I write the new ones into the db. That's the purpose of the $wpdb ...
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
252 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
votes
1answer
272 views
Checking if meta_value exists for any user
I'm using gravity forms for a sign-up form and I set up a hidden field that is automatically filled with a random string generated and passed to the form by
...
-1
votes
1answer
316 views
How to combine jQuery in-place editor with $wpdb->update
i am trying to use jQuery in-place editor (http://code.google.com/p/jquery-in-place-editor/) on WordPress to update certain values of a custom made table in my database.
I am not really skilled with ...
1
vote
2answers
326 views
Why am i getting this error? WordPress database error: [Query was empty]
I am using Wordpress 3.4.2, latest version! I have no plugins installed except the one that I am writing.
So Here's the deal, I'm reading a json feed and i'm trying to import its content into a ...
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
518 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
3answers
190 views
pull custom fields values from wp-database in a nested foreach loop
I am trying to display custom fields on my template values of which i am pulling from postmeta table
doing something wrong with a loop or not writing the foreach args correctly not sure whats the ...
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.*,
...
1
vote
3answers
156 views
Detect featured image among the attached images
I use the following code to extract the attached images from a post with ID:
$args = array(
'post_type' => 'attachment',
'post_parent' => $product_id,
...
0
votes
1answer
247 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 ...
1
vote
1answer
416 views
Problem in creating table through plugin code
I'm using the following code to create the database table using plugin.
However, the table is neither getting created nor I'm getting any error message.
The code is as follows:
global $wpdb;
...
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
1answer
86 views
Using WPDB to output raw XML fails because of wp-blog-header.php
I'm coding a plugin. One particular file of this plugin is supposed to pull data from the plugin's custom DB table, and output it with minimal processing as raw XML.
The problem is, to get the WPDB ...
0
votes
1answer
321 views
Creating an auto result search bar
I'm trying to create a search bar that will show me titles of posts when the user types into the text field.
I'm completely new to this and I really don't know how to go about doing this. What would ...
0
votes
2answers
92 views
Build index page from custom fields
Im starting to delve deeper into Wordpress custom fields and wanting to replicate this page in Wordpress:
http://www.clubsact.com.au/corporate/index.php
So my site is not tightly structured to a ...
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 ...
0
votes
1answer
182 views
Problem adding 'has-children' class to wp_nav_menu
According to a number of references online, I should be able to use the following function to add the class, has-children, to menu items that have children under them:
function ...
-2
votes
1answer
32 views
How to dispaly post informations (such as titles) in an admin plugin menu page?
I'm trying to develop a WP plugin to show post(or page) related information (such as show all post title in a list) in an admin menu page. I tried to use "The Loop", but it seems like "The Loop" ...
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 ...
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 ...
1
vote
0answers
102 views
wpdb updating record in wordpress with json adds extra array elements
This is killing me - I keep getting magical array elements added to my updated array in WP.
For example if my query is (var_dumped below):
string(70) "UPDATE wp_mytable SET already_played = '[9]' ...
1
vote
1answer
164 views
How Can I Use $wpdb in PayPal IPN file?
I'm currently writing a plugin that requires the PayPal IPN, since the IPN is not inside the main plugin file, I have no way to use $wpdb. If you know a way to do this that will work with all ...
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 ...
1
vote
1answer
286 views
How to Get All Taxonomies AND All Terms For Each Taxonomy With Post Count Zero
Is there an easy way of obtaining every registered taxonomy and for each registered taxonomy, get all the terms for that taxonomy, and for each term, get the post count, without actually fetching all ...
0
votes
1answer
650 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
1answer
92 views
Altering term_id and name via $wpdb class
$s = $_POST['submitterms'];
$querystr = "
SELECT $wpdb->terms.*
FROM $wpdb->terms
WHERE
lower($wpdb->terms.name) like '%$s%'
";
...
3
votes
2answers
454 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
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 ...
0
votes
1answer
104 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
210 views
Wordpress db prepare
I am not trying to use $wpdb->insert, but prepare.
Insert method will have one query string and an array which includes # of data which is not defined but will be defined for each query string ...
3
votes
2answers
607 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
401 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 ...
2
votes
1answer
67 views
How wordpress accesses its own database
Hi I'm just curious as to how Wordpress accesses it's own database, meaning that when I look into an admin page like link-manager.php or class-wp-list-table.php I don't see any occurences of $wpdb.
...
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 ...
1
vote
3answers
527 views
how does $wpdb differ to WP_Query?
I'm going to write a function to return the next/prev post in a specific category. can anyone tell me what the differences would be in using $wpdb as opposed to WP_Query(); eg new WP_Query(args)? what ...
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.
...
1
vote
1answer
166 views
dbDelta only creates the last table
I'm using following install function with dbDelta as referring to the codex, articles on SO I watched out for the typical problems with e.g. one space instead of two spaced at the PRIMARY KEY ...
...
1
vote
1answer
172 views
Which action does wp_update_user triggers?
I am working modifying an ecommerce plugin, and it makes uses of wp_update_user() function, and everytime the function runs another table (created by the plugin), gets updated too. The problem is that ...
