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

learn more… | top users | synonyms

2
votes
1answer
67 views

XOR functionality for meta_query

I'm trying to resolve the problem with event displaying. An event has its start and end dates, written in meta. For example, event starts on (dmY) 03.04.2013 and ends up on 08.04.2013. Using WP_query ...
2
votes
1answer
247 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 ( ! ...
2
votes
1answer
85 views

How do I batch create revisions of all posts?

I cleaned up an old-site from pasted tags, manually created lists, etc, and I'd like to keep the old posts as "revisions", so we can easily "compare" with the old posts and retrieve/revert the ...
1
vote
1answer
38 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 ...
2
votes
0answers
280 views

post_content getting cut off on blank space on $wpdb->update

I am publishing the following post via xmlrpc <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd"> <html><head><meta ...
1
vote
0answers
47 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" ...
1
vote
0answers
350 views

$wpdb->insert() does not Insert record in a table

I'm trying to understand and get hold of the $wpdb global object but can't seem to make it work. Basically, I'm trying to insert a single record into a custom table in wordpress DB. Instead of ...
1
vote
0answers
36 views

Allow user role “salesman” to view only “client” role users

I have created two new roles in my theme, salesman and client. I want, when "salesman" is logged in to be able to view and edit only "client" users. I am trying this code (taken from an answer in this ...
1
vote
0answers
146 views

Wordpress running SQL query to update database from form

Basically I want to take information in from a form and use a separate php page to update the database. so here is the original wordpress php page (add_person.php): <?php /* Template Name: ...
1
vote
0answers
47 views

Sorting main query by custom taxonomy slug

Is there a way to sort posts by custom taxonomy (shoe_color) ASC|DESC? I would like to do this using query_posts and passing the orderby=shoe_color into it. Here is the code I'm trying to work out: ...
1
vote
0answers
116 views

Changing status of Published posts which have less Content to “Draft”

function draftpost(){ global $wpdb; $prefix = $wpdb->prefix; $wpdb->query("UPDATE ".$prefix."posts SET post_status='draft' WHERE LENGTH( post_content ) <500"); } ...
1
vote
0answers
423 views

$wpdb->get_results() returns good result only in first foreach iteration

I've got strange issue when I am using $wpdb->get_results() in content-single.php in Twenty Eleven theme. $wpdb->get_results() returns proper values only in first loop iteration. I've got simple ...
1
vote
0answers
35 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 ...
1
vote
0answers
168 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 ...
1
vote
0answers
154 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
0answers
173 views

How to display users with posts published between two dates (Sorted by Post-Count) [Multisite]

I'm trying to make a list of users who have published posts within two given dates. My attempts using WP_User_query just work for one blog ID and takes time to load because it runs through a lot of ...
0
votes
0answers
3 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
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
0answers
17 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
0answers
60 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
0answers
48 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
58 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
0answers
55 views

There is way to improve this query? wordpress get post data and some meta data

Suppose we have 2 blog with different database A and B. I want to get some post from Blog B to show them on Blog A. The problem comes when the posts have much metadata (custom field for example) that ...
0
votes
0answers
41 views

Run query once inside a loop

I am trying to prevent to much queries inside a plugin one of my plugins. I have a query inside a function which will output a complete block with some layout elements and an input element which will ...
0
votes
0answers
49 views

Best way to execute custom page-specific mysql queries

I would like to query a secondary mysql database (not the Wordpress mysql database) with page-specific queries. I've seen many answers / tutorials on setting up a secondary mysql database, like: ...
0
votes
0answers
31 views

Proper way to trigger a MySQL query via link in a plugin

I am trying to develop a module in my WordPress plugin that will delete an entry from the database. The only issue is related to the trigger action. I've tried to send my users directly to the page ...
0
votes
0answers
44 views

Using the same shortcode to show any table from the database

I have a little question for you. I want to create a shortcode that makes a table with data that I have stored in a database. But i want to send the shortcode an attribute, to specify which table ...
0
votes
0answers
38 views

$wpdb: how to use a query as a base for another query?

I've got this query: select p.ID, p.post_title, p.post_content, t.term_id, tt.taxonomy, t.name, t.slug, tt.count from bdu_posts p inner join bdu_term_relationships rel on p.ID = rel.object_id inner ...
0
votes
0answers
53 views

Update tags to 10,000+ posts with wpdb?

I have over 10,000 posts on a site which all need to have a tag added to them. WP_Query is either running out of memory or timing out on my server and in the past running large queries with this ...
0
votes
0answers
45 views

Order users by 2 custom fields in wpdb query

I've created a WordPress members site, each member is a user with the role of subsriber and has extra information set as custom fields - ie: address, contact details etc. I have the users output by ...
0
votes
0answers
68 views

Querying the DB to get sum of column from custom meta box (only published posts)

I am trying to get the SUM total of a custom meta box, from all published posts, from a custom post type. By using $wpdb I am able to get the sum from all of the posts (published and otherwise), but ...
0
votes
0answers
1k views

AJAX with Selectbox Plugins (Select2, Chosen, Selectize)

I have been searching all over the internet for tutorials on implementing AJAX actions from jQuery selectbox plugins such as Select2 , Selectize and Chosen. (these plugins look better than the inbuilt ...
0
votes
0answers
33 views

How Can I Put Meta_Compare in the Database-Query?

Yes, I know that this can easily be done with built in wp_query but I need this in Wpdb query. I have a custom field and I need to display posts where this field does not exist. By the way can I get ...
0
votes
0answers
48 views

$wpdb->prepare - supporting multiple search terms

I am trying to write an escaped SQL statement, for example: $sql = 'SELECT * from TABLE where column LIKE %searchterm% AND column LIKE %searchterm2%'; Except I don't know how to handle it, as I do ...
0
votes
0answers
25 views

After importing data to new DB with new name, receiving a constant MySQL warning

I've just spent several hours trying to understand why a WP install is really slow, I tracked it down to the database and realised everything in the db was just running super slow with the debug bar ...
0
votes
0answers
73 views

Wpdb generates too many queries

I googled for hours, then found some codes on stackexchange (http://wordpress.stackexchange.com/a/108279/108270) and created the codes below. I'm trying to get alphabetical A-Z posts lists (e.g. A B C ...
0
votes
0answers
38 views

$wpdb sort order

$meta_key1 = 'first_meta'; $meta_key2 = 'second_meta'; $postids = $wpdb->get_col( $wpdb->prepare( " SELECT key1.post_id FROM $wpdb->postmeta key1 INNER JOIN $wpdb->postmeta ...
0
votes
0answers
87 views

why is $wpdb->update() causing a DB error from within wp_set_password()

I have a page-template for my custom theme that enables the user to reset their password from the front-end. I'm calling wp_set_password() and everything runs but the password is not changed in the ...
0
votes
0answers
23 views

Calculation for each custom post type

I have a code looking like something like this: (It calculates number of registered members for each course) foreach($courses as $course) { global $wpdb; $sql = "SELECT COUNT(*) FROM ...
0
votes
0answers
30 views

Any issues changing username from wpdb in admin

I'm building a plugin that will have a custom sign up process built in. I would like the users to be able to change their username if needed, since I am using their email address as the username. I ...
0
votes
0answers
112 views

Wordpress plugin tables become corrupt

I have written a plugin that creates and uses 3 database tables. On rare occasion, all 3 database tables become corrupt but no other tables in the database exhibit similar conditions. It is pretty ...
0
votes
0answers
83 views

esc_sql inserting weird chars to DB

I am using esc_sql function for making safer SQL operations but i am mysteriously getting ? and &nbsp; in the DB table how can i avoid them. Edit : Here is my array after esc_sql() Array ( ...
0
votes
0answers
97 views

Displaying posts from last 24 hours in current category with pagination

I am trying to find a solution for this problem but unfortunately without any success. I've checked WordPress Codex (WP_Query & wpdb) and few other solutions from Internet and still I wasn't even ...
0
votes
0answers
76 views

Error inserting row into table

I am trying to insert a row into a table. Given below are the various functions to create table. insert data into the table- but its not working. Also given below is the sample output showing all ...
0
votes
0answers
97 views

Retrieve post data via WPDB class

I'm trying to figure out doing a custom query using the $wpdb Object. I have custom type posts, event_posts, that have meta data, images, as well as event dates which are input in the post with the ...
0
votes
0answers
95 views

get_query_var('paged') giving same result

I have a custom page, in that page i am using a custom select query for my search functionality. The problem is pagination not working. I used $on_page= get_query_var('paged'); for pagination. When ...
0
votes
0answers
136 views

Custom query on Wordpress custom table

I am working with a custom table where some values will be inserted or updated if they already exists, I have checked and rechecked the syntax and it seems to be working fine, if I run the same query ...
0
votes
0answers
116 views

Filter content by custom field and category

Im trying to filter an Wordpress request with 2 parameters. by a custom field (REGION) there are 6 regions by categorie, there are n-categories with 1 value per post. As result i would like to have ...
0
votes
0answers
142 views

wp_query orderby value not from meta_value

I'm using the myreviewplugin to add ratings to posts. I'm now working on the posts loop and customising the query using wp_query. Everything is working fine, but I need to expand the orderby ...