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

learn more… | top users | synonyms

0
votes
0answers
5 views

WordPress database error on a query working fine in MySQL Workbench

On activating my plugin Wordpress adds an entry to the error log... WordPress database error for query SELECT * FROM wp_c2pprojects WHERE projectid = 20 made by ...
0
votes
0answers
16 views

wordpress remove where clause in taxonomy page [on hold]

My site has installed woocommerce. When I visit taxonomy page, the below SQL is executed SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = ...
0
votes
0answers
13 views

Add delete/edit button to each row in an SQL table (Wordpress Backend)

I have a form that is submitting entries to a table in the backend of my Wordpress installation. I would like to add edit/delete buttons to each row so that an administrator can delete submissions or ...
0
votes
0answers
12 views

Returning error with WP Insert without getting an error in error log

I'm checking if a key exists in my database using $wp_db->insert() and am executing code based on the result. I know that if a row already exists it will return false and I want to use that to execute ...
0
votes
1answer
31 views

Can't update multiple rows with $wpdb query

it seems that I cannot update multiple rows to change the post_type of posts having a specific tag. I follow different method, even if it seems the good one is this one : global $wpdb; $result = ...
-1
votes
2answers
30 views

What's wrong with my $wpdb prepare

I can't get my head around this. I get this error: Parse error: syntax error, unexpected '"' in 224. The line is this between foreach $html: $html = ''; foreach ( $recent_across_network as $post ...
0
votes
1answer
17 views

Can I use $wpdb for my custom tables in the WordPress database?

I am building a custom application based on WordPress. I have my custom tables in the WP database. Can I use $wpdb to work with them, or is that class solely for the WP related tables? For example, ...
0
votes
1answer
20 views

foreach loop inside the loop creating duplicates in output

I have a foreach loop inside the loop that is getting info from a separate table. The table has a column that has an id that reflects the id of the post type so it should always be unique. When I ...
0
votes
0answers
19 views

How to operate two wordpress databases simulataneously?

I am having a situation, where i have two wordpress sites. One is for saving the data and content and other is for showing the data/content. Now the situation is, i want a user to register on one ...
0
votes
0answers
15 views

How To Structure A Wordpress Database Query?

I have an array containing the IDs of the rows I want to update: $matches = array('abc123', 'def456', 'ghi789'); Rows with those IDs must be updated so that their 'confirmed' value is changed from ...
1
vote
1answer
49 views

$wpdb->update multiple rows, like IN in normal SQL

I was wondering if it is possible to use $wpdb->update to update values for multiple rows like with IN in "normal" SQL. I want to accomplish something like this example; UPDATE [table] SET [column_1] ...
0
votes
1answer
16 views

wpdb getting avatars and author url

Running an SQL query to pull authors by votes they've received on posts. @bonger helped me out on my first post and helped me get this working great, but I created this new question since it's a ...
0
votes
3answers
52 views

Insert custom postmeta when custom post type published

I'm trying to populate the postmeta table with a custom value when a custom type ('my-solutions') is published. I've read a few threads, the Codex and Pippin's blog on this matter and tried many ...
0
votes
0answers
13 views

Processing form post data using database queries to construct custom query string

I have a form on my wordpress site. On form submission I want to: 1) Capture the form data 2) Run database queries using these data 3) Process the results and use these to construct a query string 4) ...
0
votes
1answer
60 views

$wpdb select date range of posts

0 down vote favorite Using this SQL query to sort users by how many votes(meta key) their posts have received. <?php global $wpdb; $results = ...
1
vote
1answer
33 views

Can't get result from sql using ajax result

I'm using an AJAX form to feed the code something to lookup in db. Separate table, not WP options. I'm getting the result from AJAX, but when I try to do the sql it just returns 0. This is the ...
0
votes
1answer
21 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
43 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
12 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
16 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
23 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
35 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
67 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
1answer
48 views

Hook into $wpdb

Is there a way to hook into the WPDB instance ($wpdb)? What i basically want, is to execute a own function BEFORE the desired query get's executed. Is this possible? Additional question for comment ...
0
votes
1answer
16 views

Wordpress is trimming leading 0s

I am inserting into the DB in the following manner: // insert the info into the db $wpdb->insert( 'wp_vkrwps_table', array( 'zip' => $zip ), ...
3
votes
1answer
136 views

Is it true $wpdb->get_results is faster than WP_Query in most cases?

On my homepage, I have a section where I have to display the last five featured posts, where a featured post is simply a post with a custom field is_featured set to 1. I achieved what I want with two ...
0
votes
3answers
68 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
21 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
160 views

wpdb::prepare was called incorrectly

I have this code to remove orphaned posts after deleting custom post type. It works, but this code... global $wpdb; $wpdb->query( $wpdb->prepare( "DELETE a,b,c FROM wp_posts a ...
0
votes
2answers
44 views

WPDB - How to search a column in a table

I have a custom table called wpgrating I have a column there called "ip" Now what I want to do is search for "ip" column and see if there is an entry already there? How can I achieve this?
1
vote
0answers
53 views

How to query custom post types with mixed AND & OR statements for custom fields

I have a custom post type "events" which includes the custom fields "is_premium" (which is a true/false) and "premium_expiry_date" which is a date picker. On my front end, I want to have "events" ...
0
votes
1answer
40 views

Get the alphabetical sorted data with wpdb

I have a function in my WP which get the data from database, Here is the function function thebook_get_provider_types() { global $wpdb; static $provider_types; if (! ...
0
votes
1answer
32 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
31 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
25 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 ...
2
votes
1answer
57 views

How to update records using $wpdb?

I am migrating non-wp database to Wordpress (for the first time in my life, and hopefully the last). As both new and old websites are multilingual, one of the tasks for me is to connect the articles ...
0
votes
1answer
31 views

Active DB queries in Wordpress?

I just make some researches regarding to wordpress DB queries and I just wonder if I miss something a normal SELECT query for example in Codeigniter with active records would look like if I assume I ...
0
votes
0answers
97 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
38 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
57 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, ...
1
vote
1answer
77 views

wpdb insert and boolean fields

I'm preparing an insert query like this: $wpdb->insert('table', $data, $format); data array will be: $data = array_push($data, 'resp' => true) problem is, what $format shall i use for a ...
0
votes
1answer
47 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 ...
1
vote
2answers
445 views

WPDB Insert or if exists Update

I'm not crazy familiar with WPDB or SQL in general but I have a custom table for my project and I'm trying to assign some metadata to it. What I'd "like" to happen is if a row exists, update it and if ...
0
votes
2answers
346 views

Alternative to mysql_real_escape_string

I have a WordPress plugin that at one point I need to see if a certain title exists in the database. For 2 years, this code worked fine: $myposttitle= $wpdb->get_results( "select post_title ...
1
vote
1answer
56 views

Select two sums with single get_var statement

I am trying the following global $wpdb; $sum = $wpdb->get_var("select sum(first), sum(second) from table where id > 1"); I am unable to get the values from each request. I have tried ...
0
votes
2answers
60 views

Extracting the post_id via the wp_insert_post action (external db query)

i'm writing a little action plugin. everytime a new post is created, a new table should be created in an external db. The name of the table sholud reflect the post_id of the newly created post, but i ...
0
votes
0answers
61 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
1answer
55 views

Custom SQL Query passing array to WHERE p.id

I need to pass an array of post ID's to a custom SQL query I am running on a certain page. The query looks like this: $querystr3 = "SELECT *, events_startdate.meta_value AS the_start, ...