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

Ordering list of users by last name and then by first name

I have a page listing users with certain custom roles, ordered by last name in alphabetical order. So far, so good. The problem is when two users have the same last name (i.e. John Doe and Rick Doe). ...
0
votes
1answer
17 views

WPDB Table Does Not Exist

From this code: global $wpdb; $sidebar_table = $wpdb->prefix . 'w3care_sidebar_position'; $checkad = $wpdb->get_results( $wpdb->prepare( "SELECT ad_id, sidebar_position, ad_type FROM `%s` ...
0
votes
1answer
18 views

Wordpress Insert not working with ajax

I am trying to enter insert data with form in wordpress and want to use ajax for that. Without ajax it works fine but when I use ajax pressing the submit button gives 0 in result and the data is not ...
0
votes
0answers
24 views

Query postmeta values, and return multiple post_titles for common meta value

As of now I query the DB: global $wpdb; $query = $wpdb->prepare(' SELECT p.post_id, p.meta_value, pm.post_title FROM %1$s AS p JOIN %2$s AS pm ON ...
1
vote
2answers
39 views

$wpdb->replace / Replace or update primary key

I write code to save data in to the database table. I want Replace a row in a table if it exists or insert a new row in a table if the row did not already exist. ...
1
vote
1answer
15 views

How does the WXR file differ from the WPDB?

I'm looking to make it so an administrator can do a complete backup of a WordPress website with the click of a button in the administration pages. In doing so, I figure the code would need to backup ...
0
votes
1answer
16 views

Query Custom Fields in Searchform

In my searchform.php I want to query the values of a custom field, add them into a dropdown, and return a link to a corresponding page upon submit. Thus far I can create the values dropdown: global ...
1
vote
1answer
11 views

Why $wpdb->show_errors() and print_error() is showing an output even if the query output is correct?

In order of figuring out the following issue, see Sanitize a working query string by using $wpdb->prepare() fails with MySQL DB error "right syntax to use near '3' at line 1" i ...
0
votes
0answers
20 views

Ajax Form data is not posted back to the get_results()

I am trying to run a wordpress wpdb->get_results select query and I want to get the search criteria from a textbox. I want to do it form and with ajax without refreshing the page. No matter what I do ...
0
votes
0answers
28 views

Sanitize a working query string by using $wpdb->prepare() fails with MySQL DB error “right syntax to use near '3' at line 1”

I was using the following properly working query so far: $querystr = " SELECT wposts.* FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta1, $wpdb->postmeta wpostmeta2 WHERE wposts.ID ...
0
votes
1answer
23 views

Ajax Query returns zero

I am doing simple wordpress select query and want to do this with ajax jquery and do not want the page to refresh when I press search button and writing text in search textbox. As soon as I press ...
0
votes
1answer
26 views

Search query with Ajax

I'm running a $wpdb select query and getting it’s parameter from a textbox. Result shows as soon as I press the search button, but I want to do the same with Ajax without refreshing the page. I have ...
0
votes
0answers
26 views

Update all fields of table with ON DUPLICATE KEY UPDATE command

I write code with $wpdb->insert command into the database table wp_coin_price. After inserting data in the table, I write code to update all fields with ON DUPLICATE KEY UPDATE, but it's not ...
0
votes
2answers
42 views

$wpdb->query can't insert data

I Write Code to Save data in the Wordpress database table (table name is wp_fafa) But Can't Save data in $qry = $wpdb->query( "INSERT INTO `wp_fafa` ...
0
votes
1answer
10 views

Why won't this wpdb get_results query return results?

Having trouble with this query. It returns an empty array even though I know the variables are correct and that multiple rows exist in the database that match. $results_a = $wpdb->get_results( ...
0
votes
0answers
19 views

Using $wpdb (WPDB class) 'replace' with multiple WHERE criteria problem

I have two fields that are used to identify a particular row (acting as a composite key). If it does not exist, I wish to insert a new row. The REPLACE function ...
0
votes
1answer
17 views

WPDB for post count on post

I figured out how to show the count of a custom post type on author.php . I am trying to display the stats on their custom post as well. The same query does not work. How can I show the amount of ...
0
votes
1answer
23 views

MySQL queries in Wordpress

I have a MySQL database table called stock which holds a stock record on items for sale. When querying the database using PHP I have no issue, but when I try to do it through WordPress it doesn't ...
0
votes
2answers
31 views

Shared Custom post type between WP network sites

I'm developing four websites which are separate, besides the Events (custom post type). Three of the websites are WP, and I've got them in a Network. I would like Events to show up in all three Admin ...
0
votes
0answers
29 views

wpdb query using duplicate key to check update/insert

I am trying to use the query below to insert a row into my wp_postmeta table. If this row exists already e.g the meta_id key is not unique I need it to update this row with the meta_value at the end ...
3
votes
2answers
94 views

Return only Count from a wp_query request?

Is it possible with the standard build-in tools in Wordpress to get wp_query to only return the count of an query? Right now, I’ve a query which has several meta_queries but what the only thing I’m ...
0
votes
0answers
23 views

Created a function similar to facebook events with [ Attending / Not attending ] options

I modified and extended an event plugin on wordpress that is being hosted on GITHUB then finally came up with this idea in a separate PHP file and added options such as the ATTENDING and NOT ATTENDING ...
0
votes
0answers
8 views

Wordpress - wpdb query does not list same result as sql query

I have a very weird issue with wpdb which is freaking me out. My database has the following data: INSERT INTO `wp_clb_likes` (`id`, `post_id`, `user_ip`, `time`) VALUES (5,11511,'::1','2015-01-25 ...
0
votes
2answers
42 views

Displaying data from another database

I'm working on custom plugin that will pull property information from our non-wordpress database. That is working just fine. Where I'm having problems is getting the whole front end piece to work. ...
0
votes
1answer
54 views

Protect custom form from SQL injection

I'm trying to understand how to protect my custom form from possible attacks. I send a data via a form, let's say userdata, then I read it: $userdata = $_POST['userdata'] I put it into an array to ...
0
votes
0answers
18 views

why nl2br() is adding an extra <br>?

I store the text with wpdb->insert. While retrieving it with wpdb->get_results I echo it with nl2br() function to preserve the new lines (or it will be echoed without line breks). Problem is ...
0
votes
1answer
24 views

Retrieve a list of users based on some conditions

What am I doing wrong on this query? The main issue is the var_dump returns null. The query works fine in phpMyAdmin. global $wpdb; $users = $wpdb->get_results( $wpdb->prepare( ...
0
votes
1answer
18 views

Write mysql credentials in plugin

I've to create a custom plugin to print data from a database different from the wordpress one. I'm using wpdb. Is it fine, from a security point, to write database credantials in the plugin files in ...
0
votes
1answer
26 views

Doubt using $wpbd->get_col for a single column

$table = $wpdb->prefix . 'posts'; foreach ( $wpdb->get_col( "DESC " . $table, 0 ) as $column ){//get all columns from wp_posts echo "<div><p>". ...
0
votes
1answer
43 views

Using wpdb without loading all plug-ins via wp-load.php

I'm trying to prevent WP from loading all plug-ins when including wp-load.php, since I don't really need them nor the usual WP actions/filters. All I need is the WPDB class to query the database ...
0
votes
1answer
35 views

pre_get_posts or $where, which one to use?

i have a custom search widget, that is searching only one custom post type that contain a meta_key that is greater than or equal to 1, in which i am gathering post_id. of all of those post_id(s), i ...
0
votes
1answer
21 views

using same mysql user with many databases

As we know that in order to connect WP with database we should to define mysql username and password in wp-config.php, so at that point i have a question regarding security or ( some sort of ...
0
votes
1answer
29 views

WP Sql query multiple where clause

I'm trying to get the users that have registered after a specific time (this case $today) and who have the newsletter field true and the account false. This is what I have so far but the result is ...
0
votes
0answers
21 views

How to query for the first 5 elements published?

<div class="content left"> <div class="wrapper"> <div class="gallery-single-content left"> <div class="gallery-filter left" style="display: none;"> ...
0
votes
0answers
38 views

What is the best practice to initialise $wpdb by loading wp-load.php?

Why do users with high reputations suggest loading wp-load.php with a full path? My question is simple and was originally intended as an answer to this question. However I do not have a high enough ...
0
votes
1answer
68 views

Problem on wpdb queries, wp_insert_post, wp_insert_user etc. The query runs twice

Anyone encountered this issue? I have created a custom php script which adds a new post by using wp_insert_post() but everytime I run the code it creates a 2 new post where in it should be only be ...
0
votes
1answer
36 views

Using WPDB->Insert()

Hello I have been developing in PHP and now am just starting the transition to Wordpress. In PHP I have this -> // Prepare statement $sqlstatement = $conn->prepare("INSERT INTO importtest ...
2
votes
1answer
32 views

Wpdb query for comment meta for current post

I have a comment meta field that displays a rating for each comment, I was wondering if there is any way I can query the database to get the sum total of these ratings for each post. I have included ...
0
votes
1answer
13 views

Save sql file after doing insert wpdb

My code below takes an xml file and inserts it into a database table. However, I would also like to save the full insert query as a backup. Is it possible to write out the query built by wpdb so that ...
0
votes
1answer
50 views

WPDB secure custom form

I'm creating a custom form to update rows in a secondary MYSQL DB, different from the one of wordpress. This form is public and every user can access it. So I've created a plugin and I'm using also ...
0
votes
1answer
54 views

WPDB update row with != in where clause

I'm using wpdb to develop a plugin to add a custom form to wordpress. To update a row, I use an array and wpdb->update(). WP Class Reference says: My SQL code should be something like UPDATE ...
0
votes
0answers
12 views

Problem by dispaly inserted form

I've build a form and insert it's data into custom db by $wpdb. When I click on the submit button, page reloads and one row added to db but noting displays on website. You can see it at: my site ...
0
votes
0answers
26 views

why not changing site body after insert row by $wpdb?

I've create custom table and insert, update and delete it's values by $wpdb My problem: when i click on submit or send button, despite changing value in database (add a row, update value and ...), ...
1
vote
2answers
95 views

Add meta value to custom post type on publish

I have a client who is requesting that all posts of a certain custom post type (called 'custom-jobs') be set to automatically be included in the sitemap in the Yoast SEO plugin. I found that in ...
1
vote
2answers
34 views

How to get entry by title by using wpdb

I've create a form by metabox and save data in custom table my table is: $table_name = $wpdb->prefix . 'aacv'; $sql = "CREATE TABLE $table_name ( id int(11) NOT NULL AUTO_INCREMENT, ...
1
vote
1answer
66 views

convert custom query to wp_query

I have used classipress theme My query is as below $querydetails = " SELECT wposts.* FROM $wpdb->posts wposts INNER JOIN $wpdb->postmeta wpostmeta ON wposts.ID = wpostmeta.post_id ...
0
votes
0answers
15 views

WP DB Location for “Next Post to Create” Index Value

I have a malformed DB (no mystery here, I deleted some data directly rather than through the WP admin interface). I've deleted all posts and meta for 400+ but when I create a new post, the sequencing ...
1
vote
1answer
25 views

Alter a specific query on Wordpress

I need to change a query of a plugin that is not the main query. The author did not put any filters. I can see the query from $wpdb->queries Is there a way to access the specific query and ...
0
votes
0answers
44 views

Fetching array of postmeta with $wpdb and in_array conditional

I'm trying to fetch an array of all entries to a specific meta key and then check to see if the user input value exists in that array. I've checked the data base for the query and I see the meta ...
0
votes
0answers
17 views

Custom table in my plugin print UTF-8 (מוברש) charsets and not hebrew

i have created custom table in wordpress db to use my plugins needs. i have campaigns with hebrew names, this saved to column (varchar(100) utf8_unicode_ci ) in the DB i dont see hebrew but this: ...