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
437 views

Placing a widget with $wpdb query

I'm getting the feeling that adding Widgets via MySQL query is not as simple as I thought. I was under the impression all data is stored in the options table, but it seems like I was wrong. Any idea ...
0
votes
1answer
12 views

Multi-site site nav, wpdb->prepare missing argument

I'm using a Wordpress Multi-site to house a number of sites in one WP install I'd like to have a nav showing each site with a link to the site. I'm using this function to do this <?php ...
0
votes
1answer
18 views

Exclude specific terms from all queries using posts_where or something similar

Basically what I'm trying to do is exclude all posts that belong to a specific set of terms from showing in any and all queries across the board, EXCEPT when you're actually viewing that post or page. ...
0
votes
1answer
21 views

WP_USE_EXT_MYSQL

Here is the constructor for the wpdb class as found in the source code. According to a google search this has been recently renamed from USE_EXT_MYSQL. However I cannot find anywhere in the source ...
0
votes
1answer
6 views

wpquery properties last_query and last_result : should these be public or private?

I've come across the following lines of code in wp-includes/wp-db.php: /** * Last query made * * @since 0.71 * @access private * @var array */ var $last_query; /** * Results of the last query ...
0
votes
1answer
27 views

Ascending order of yearly archives

Hey there, I stumbled upon this question but I can't seem to contact the author, because I'm still too new here. I'm using this snippet on my archives.php page to display my posts sorted by years. ...
0
votes
1answer
26 views

Using $wpdb in a plugin, what sort of data does it return?

I have following code: <?php $q = intval($_GET['q']); global $wpdb; $myoption = get_option( 'fixformdata_options' ); $myoptionValue = maybe_unserialize( $myoption ); $result2 = ...
0
votes
1answer
20 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
29 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
1answer
18 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
1answer
68 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
1answer
59 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
2answers
46 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
43 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
112 views

How to access the WordPress DB from a plugin file

I'm building a basic video management plugin, with an embed feature that will have URLs like: mysite.com/wp-content/plugins/embed-video.php?video=[POST ID] I plan on using the [POST ID] url parameter ...
0
votes
2answers
186 views

Undefined variable: row?

I'm trying to select the post_title from wp_posts with a query which I did using this method: global $wpdb; $test = $wpdb->get_var( $wpdb->prepare(" SELECT post_title FROM ...
0
votes
2answers
78 views

Short of raw SQL, can I query for multiple attachment metadata that have a given array key?

With raw SQL through $wpdb, I believe that I could do something along the lines of this (untested): SELECT post_id, meta_value FROM postmeta WHERE meta_key = '_wp_attachment_metadata' AND meta_value ...
0
votes
1answer
72 views

WP MS: How to query over the network

I have a WP 3.8.1 Multisite installation with 3 blogs, they're all in one db, prefixed wp_, wp_2_ and wp_3_. In a template in wp_ I try to to display all posts from wp_, wp_2_ and wp_3_ which have a ...
0
votes
1answer
112 views

List users with the most posts in the last 30 days

I'm trying to create a MySQL query to display a descending list of users with the most number of posts over the last 30 days. This is not working with me: $where .= " AND post_date > '" . ...
0
votes
1answer
87 views

Are term_taxonomy_id and term_id the same?

I have a custom query where I need a JOIN because I want to COUNT all the posts of a specific category. So I checked the tables and I found out that table wp_term_relationships contains a reference ...
0
votes
1answer
194 views

Add row to custom database Table and delete all rows older than 1 day

I'm editing a view counter plugin so that it logs the IP of every user that viewed a post. This is to prevent them from refreshing the page and thus creating artificial views. The part I'm having ...
0
votes
1answer
41 views

$wpdb in php 5.5

I am helping a friend update their website and move it over to a new server. Their old server is running php 5.3.6-13 and the new site is running php 5.5. There is a custom plugin that uses $wpdb ...
0
votes
1answer
422 views

How to return count of custom post type posts with a specific custom field value via $wpdb?

I am trying to get count of a custom post type with a specific custom field value from wpdb without doing a WP_Query or get_posts since I think it is more resource efficient and I need to return 10 ...
0
votes
1answer
27 views

remove all custom post created

i will automatically create a lot of post with the wp_insert_post function <?php wp_insert_post( $post, $wp_error ); ?> all those custom post type will be call "house" and then after some ...
0
votes
1answer
56 views

How to optimize multiple insert into wordpress database

I had main file with my plugin and the another file with sql command. In the second file I create two tables and write data to one of them. But I have problem with. In my private computer everything ...
0
votes
2answers
46 views

Help setting up a sql query

I need to list out specific custom field items that contain an associated custom field entry. For example, the custom fields are named "type" and "food". I would like to list out all of the breakfast ...
0
votes
1answer
98 views

access JSON results from wordpress database with wpdb

I have JSON results from Google API added to to wp_options table. At this point I just need to echo the specific elements. Namely, the coordinates. The option_name I have is py_menu_item. One of the ...
0
votes
1answer
175 views

$wpdb->get_results not returning an array

I haven't really messed with $wpdb before, but I'm stuck hard on one part. I'm trying to get the values returned in an associative array. I've tried both of these $datarow = ...
0
votes
1answer
164 views

Query custom taxonomy for category including children

I've using the Events Manager plugin which creates a custom post type of 'event' and a custom taxonomy called 'event-categories'. I have the category 'courses' which has an ID of 43. I also have a ...
0
votes
1answer
281 views

Insert two row in wordpress database

Hello I am working on a template where I have to grab some value and insert them in my own created table in wordpress database. Now as I dont know how to insert record in wordpress database , so i am ...
0
votes
1answer
111 views

get data with shortcode

i have a wp db. and i added a table "wp_mapmus" now i want to show these datas on post page with shortcode. But there is an error. and i dont know php very well. i only use same plugins. what is the ...
0
votes
1answer
641 views

WordPress database error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version [closed]

after wordpress update to 3.5+ i get error in this plugin. I do not understand how to fix it. If anyone can help me with these problem or give me an example of how to fix it here is the full code of ...
0
votes
1answer
242 views

Can I use wpdb to insert query results into a post?

My website currently consists of content drawn from database queries, displayed with php. Specifically, there are 4 modules, each of which queries a different database to get all records that match ...
0
votes
1answer
148 views

Delete/replace img tags in post content for auto published posts [closed]

In my blog I have set up auto-publish for posts and I get 5 thousands new posts every day, in this moment I have more than 150 thousand posts. I need a script, or a plugin, or a function to connect ...
0
votes
1answer
149 views

I'm not able to get access to $wpdb [duplicate]

I'm developing some additional functionality with a jQuery autocomplete form, some custom database tables, and PHP to query the tables. I have it working outside of the WordPress framework using ...
0
votes
1answer
33 views

query a newly created table using $wpdb

i created a new table inside my wordpress database called forms, this table consist of ID and names i want to query all the list from this table using the wordpress $wpdb this is my code below ...
0
votes
1answer
83 views

wpdb_prepare with multiple or condition

I want to execute a query like this: $wpdb->prepare( "SELECT * ... from ... WHERE ( post_title LIKE '%%%s%%' or post_content LIKE '%%%s%%' )..., $string ); If I do the query with only one ...
0
votes
3answers
562 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
1answer
532 views

Call to a member function get_row() on a non-object, Unable to use global $wbdp inside a plugin

I am building a custom plugin for my WordPress site. I made a php file called "checkrank" that obtains data from a custom table named "cranking". $uid = $GET['id']; function checkExists($id){ ...
0
votes
2answers
2k views

Getting value from database table depending on field value

I am using a plugin called formidable which is similar to Gravity Forms in terms of purpose. I have two fields of interest. The first field loads up all the values in the Town column of my ...
0
votes
1answer
63 views

WordPress Mysql query and Duplicate

i've a problem with mysql query on my wordpress database. I've custom fields Country and City. At moment I have this query that show all the cities of "UK" Country $querystr = " SELECT wposts.* ...
0
votes
2answers
109 views

$wpdb is queried but results don't show

I am trying to show a list of custom post types on a page template. When I view the page, instead of seeing the different posts, I see the actual page repeated. For example, If I have 5 posts, the ...
0
votes
1answer
49 views

select a single val though a table in wordpress

The table is like this: category_id category_name category_parent_name I would like to get category_id by using category_name. I searched online, and the code is like below: $ad_cat is the ...
0
votes
1answer
181 views

Plugin to create Posts and Forums then choose category and parent forum

I need to create a plugin for a customer that will help him create posts and forums and place them in a category and choose if it's a parent or a child forum. Just created a GitHub Repo for my files ...
0
votes
1answer
46 views

$wpdb->update Issue

Can anyone see what I have wrong here? $wpdb->update( $table, array( 'lat'=>$paper_lat, 'lon'=>$paper_lon ), array( 'id'=> $result=>id ...
0
votes
1answer
159 views

wpdb prepare sql problem

I have problem with wpdb prepare and sql query. If i run the query directly thru wpdb->get_results it's working fine. Here it is: $alabala_sql = $wpdb->prepare( " SELECT * FROM ...
0
votes
1answer
222 views

Get all sticky posts from one user through user ID

So I need to get number of sticky posts each user have and compare it to one variable. I managed to do this, but I am wondering is this the right way to do it. //Retrive all sticky posts ID ...
0
votes
1answer
88 views

WPDB Query Question with Category Only

I am trying to pull up posts from only category ID 18 with this query for a plugin I am working on but it will not work. I can not use query_posts or WP_Query in the place I am using this. global ...
0
votes
1answer
856 views

How-To: wpdb Insert Record With Date

I am writing a plugin where I need to pre-load some data in the custom tables that I create upon Activation. My inserts have run fine thus far until I attempt to insert a record with a DATE datatype. ...
0
votes
1answer
76 views

How do I query for posts by custom meta and those that have been stickied?

I realize how clumsy and inefficient this query is but SQL is not my strong point. I use the following query to pull the latest 8 events from a custom post type called Event Posts. However, I also ...