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
19 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
vote
1answer
299 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 ...
0
votes
1answer
452 views

How to check for empty and not a failure

I'm querying the postmeta table to see if a url has already been entered, using this statement (where $thisLink is the url I'm checking) $mypostids = $wpdb->get_results("select * from ...
-1
votes
2answers
29 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
14 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
17 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
1answer
240 views

wpdb inside foreach loop only returns first result - 2 other similar cases found

@Milo Problem solved, found spaces in the array $arrname. I was trying to get post id using post_name. First of all I stored all post_name in an array an then loop through the array to use the key ...
2
votes
2answers
3k 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
0answers
14 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 ...
0
votes
1answer
391 views

wpdb->insert multiple record at once

So after I have created the table 'settings-table' i want to add a couple of records to it. This is how I want to do it, not the best way, so I need a better way to do this because I will add more ...
1
vote
1answer
37 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
14 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
47 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
1answer
57 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 = ...
0
votes
0answers
9 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
20 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 ...
1
vote
1answer
31 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 ...
3
votes
2answers
546 views

How might I retrieve a featured post image from an external WP site and display it as a link back?

I have two WP sites. I want to reach from one of them, into the other, and retrieve specific featured images for posts, and display them with a link to that post. I am using this line (with the ...
0
votes
0answers
39 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
11 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', ...
2
votes
1answer
251 views

Change post status based on meta value

I have this cron set up to trash posts x days after it is posted. This works. Edit: Added my answer to my question. add_action( 'wp', 'do_trash_ads' ); function do_trash_ads() { if ( ! ...
1
vote
4answers
6k views

get_results using wpdb

im trying to retrieve information on my wordpress database, i wanted to display all pages using this statement. but im getting a blank ARRAY global $wpdb; $result = $wpdb->get_results ( " ...
0
votes
2answers
2k views

Using $wpdb to query posts with meta value containing current post_id

I am trying to to use $wpdb to retrieve a list of posts from the Database where the meta_value in the wp_postmeta table contains the current post_ID in inverted commas. eg. "10" The inverted commas ...
2
votes
1answer
54 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 ...
1
vote
2answers
2k views

How to insert data to a database table when the field is not yet created?

Supposing I have an existing table(already created in dB) that handles user-registration (a plugin) and insert data using the $wpdB->insert like this: $success = $wpdb->insert( ...
0
votes
0answers
20 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
34 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 ...
3
votes
1answer
122 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
1answer
59 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 ), ...
0
votes
3answers
486 views

How to Modify this $wpdb query to accept an array of post statuses

I'm using this function from this accepted answer, which gets all values for a custom field key (cross-post). How could it be modified to allow an array of post statuses? function get_meta_values( ...
0
votes
3answers
62 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
2answers
43 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?
0
votes
1answer
143 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 ...
1
vote
0answers
52 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" ...
2
votes
2answers
591 views

How to programatically change username (user_login)?

As in the title, how to programatically change user's login? I wanted to use wp_inser_user function, but it appears that when updating current user, it doesn't change his/hers username. Should I use ...
0
votes
1answer
29 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
38 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
0answers
92 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
28 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
23 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
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
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
37 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, ...