The wpdb class, accessed via the $wpdb global variable, is used to interact with the WordPress database

learn more… | top users | synonyms

0
votes
1answer
173 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
672 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
513 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
262 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
1k 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
155 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
2answers
281 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
1k 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
109 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
59 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
422 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
268 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
496 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
797 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
324 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
294 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
266 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
1k 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
3answers
5k 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 = ...
0
votes
1answer
94 views

Why doesn't my Table get created?

I am working on creating a table in the DB for a plugin but cannot figure out why the table is not being created. Here's my code: global $ds_swoons_db_version; $ds_swoons_db_version = '1.0'; ...
0
votes
2answers
940 views

How do I modify this wpdb query to include posts that have a post_status of publish and draft?

I'm using the following function to count the number of posts an author has made from a custom post type. <?php function count_user_posts_by_type($userid, $post_type) { global $wpdb; ...
0
votes
2answers
173 views

How to query and update one colum in postmeta table?

I'm trying to make a popularity calculation for all posts, based on page view and date of creation. Initially, there's a default popularity value saved in postmeta. Every hour I want to recalculate ...
0
votes
1answer
794 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
1k views

Query and get meta as object(stdClass) on wp postmeta table?

I want to get a groups of data from postmeta table. The postmeta table have 4 colums, meta_id, post_id, meta_key,meta_value. Each post_id has a list of meta_keys. I want to run a query and get a ...
0
votes
1answer
370 views

Subdomain redirect problem

Wordpress is installed my root directory(/root/). I have a subdomain(dammani.techbrij.com) and I want to access some files of main domain from sub domain. I have done following thing: ...
0
votes
1answer
271 views

How do I query a table?

I am using Contact form 7 and the database extension, the db extension creates a table called wp_CF7DBPlugin_SUBMITS. I have 2 forms on my site, I need to know if the user has completed the 2nd form, ...
0
votes
1answer
6 views

Save/retrieve form data best practises for theme development

I'm building a theme and I have a custom page template with a <form> which is for the vistors to fill in and submit. I'm processing the data with help from hooks and this is all separated from ...
0
votes
0answers
22 views

Fire query on ajax post url page

Here i am sending the ajax response to load_post.php page from my ajax call.I am getting response on load_post.php on load_post.php i have to fire word press query. I was try this but getting bellow ...
0
votes
0answers
6 views

How to detect if website has a mapped domain attached to it on multisite network

I'm trying to to detect if a website has a mapped domain attached to it on a multisite network. If not, disable search engine visibility. This is what I have so far: //* Disable search engine ...
0
votes
2answers
12 views

Wordpress insert NOW() in TIMESTAMP column returns all zeros

I want to insert a TIMESTAMP into my column's TIMESTAMP column, but I always get all zeros. Here is my insert: $now = 'NOW()'; // insert the date into the db $wpdb->insert( 'wp_date', ...
0
votes
0answers
16 views

WPDB update is not working for tables with large number of columns

I am using a form to update a cutom WP datatable. The update function is working fine for all the table except one which have 14columns. I can delete the rows but can't edit any entries. For edit I am ...
0
votes
2answers
33 views

Perform a function when a user clicks register button in wordpress

I am kind of new to wordpress coding. I'm trying to edit the wp-login.php file, in which, if a user clicks register button, it registers the user and stores an information on a different table in the ...
0
votes
1answer
42 views

Action hook “wp_insert_post” works but not for last imported post

I want to run a custom function whenever posts are imported to my custom post type. I am currently running this code - function on_post_import($post){ global $wpdb; $results = ...
0
votes
3answers
43 views

How do I check for a duplicate record before inserting using wpdb

I am inserting a row into a custom table in a wordpress database. this is the code: $wpdb->insert( 'wp_pl_my_parts', array( 'user_ID' => $user_ID, ...
0
votes
1answer
17 views

Echo only gives me the first part of string

So I was pulling some meta_value and trying to use it in a mass email and tested it first by echoing what I obtain in the array. In var_dump I see the array and that it gets my correct data, but when ...
0
votes
1answer
24 views

store custom WP table names in a global variable

I was being creative and put this in one of the files loaded with my plugin. Are there implications with storing the table names this way? global $wpdb; if(!defined('DB_ARTISTS')) ...
0
votes
1answer
23 views

$wpdb doesn't like to store arrays

I'm attempting to store an array that looks like the one below, into a cell in a database using the code below the sample array. Unfortunately, WordPress doesn't seem to want to save it, and ...
0
votes
1answer
21 views

Pulling values from a sepcific row in table

I'm trying to get the first and last name values for ONE person in a database where the meet certain conditions of being a team leader and having a specific project id. Because of this, it will always ...
0
votes
0answers
57 views

How to add more custom fields in user meta table simultaneously

I am working on a task in which i have to submit some records to user_meta table at form submitting. Actually it is related to employee data and i just want to add records in user meta table. I am ...
0
votes
1answer
26 views

wpdb->insert adds too many rows

I have the following code in my functions.php $ar = array( 'price_content' => 'hello' ); $result = $wpdb->insert('hs_prices', $ar); // insert 'hello' into 'price_content' This should ...
0
votes
0answers
5 views

WPDB Prepare error [duplicate]

I have just taken hosting on for a clients WP site and I am stumped with a WP error The site originally ran on 3.2 but I am upgrading to 3.9 and the client has an error on their them caused by a ...
0
votes
1answer
36 views

Slow getting posts from category

My blog has over 700,000 articles and my category structure as follows: -Cats Cat 1 (ID: 3) Cat 2 (ID: 4) Cat 3 (ID: 5) ... Cat 20 (ID: 22) I took the articles by using the following SQL ...
0
votes
1answer
46 views

How to make an sql query to exclude everything but custom taxonomy terms in table wp_terms?

Problem Summary: I am trying to write a SQL query that returns only my custom taxonomy terms, but the table (wp_terms) contains all of the terms, even ones that I don't want (such as category terms, ...
0
votes
1answer
39 views

Search Query that Includes Custom Table

I have a WordPress website that grabs product data from a custom table. I would like to be able to also search from fields in the custom table. Could someone provide a sample query of what this would ...
0
votes
0answers
46 views

Query Distinct Taxonomies of Custom Post Type

I have a custom post type called "coupons". These coupons can then be drilled down by "city". City is a custom field that is defined for each individual "coupon". I am then trying to modify a sidebar ...
0
votes
0answers
55 views

Get thumbnail using wpdb from external wordpress database

I'm trying to get thumbnails from posts using a wpdb query where the wordpress database I'm querying is not the one from which the wpdb query is being called. That may be a little unclear, so here is ...
0
votes
1answer
32 views

wpdb->update error

I am trying to update the value of an entry in the gravity forms detail table. I am simply trying to update the 'date' field inside of an entry. Here is my query: $update_date = ...
0
votes
1answer
27 views

Cannot update custom database table row

I am trying to update a row in a custom database table by $wpdb->update();. In my opinion my code is right but for some reason my database row doesn't update. Can anyone help me with this? I want ...
0
votes
1answer
164 views

$wpdb->prepare with ON DUPLICATE KEY UPDATE

I just took this code from $wpdb Codex page, and modified my existing Insert query: $table = $wpdb->prefix . 'user_req'; $post_id = explode('_', $_POST['post_id']); $user_id = $_POST['user_id']; ...
0
votes
1answer
32 views

How do I count columns on a custom WPDB query?

How would I count the columns of a custom WPDB query? This does work although I need a different kind of output: $sql_assoc = "SELECT * FROM test"; $num_cols = count((array) current($sql_assoc)); ...