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

SQL query not working in alphabetical post title/content search

I have an ajax request using wp_ajax sending one variable named "q" what I want to do is after the script get's the request to look inside the db and fetch the title and id of the corresponding posts ...
0
votes
1answer
545 views

Wordpress db prepare

I am not trying to use $wpdb->insert, but prepare. Insert method will have one query string and an array which includes # of data which is not defined but will be defined for each query string ...
0
votes
1answer
250 views

Why does this WPDB code throw an empty WPDB error? [closed]

I'm writing a feed reader plugin for wordpress. I'm seeing a DB error that I can't figure out. First I create a table called user_entries. Then I put a sample entry into that table. When I try to ...
0
votes
2answers
348 views

wordpress $wpdb works only once

I am working on a plugin that needs to run many different queries. I created a class that has many functions and all these functions runs different queries. A DAL basically. Now when I call these ...
0
votes
1answer
487 views

$post not working working in AJAX plugin with custom post type

I am trying to create a plugin that can relate two posts to each other, and to do so I am trying to use AJAX, but I am having trouble getting the current posts ID using $post->ID. I am trying to ...
0
votes
1answer
2k views

Join inside a wpdb query.. confused!

I need to get a return from a query that provides me with email, username or nicename as well as post title based on author id. The query is to run once daily via cron and look for posts that have ...
0
votes
2answers
1k views

How to test the outcome of a wpdb query?

I want to get all the data with the meta key of "project_id" from post meta table. I wrote a query, it should work in thoery, but I have no way to see what I get, and inject this query to my plugin ...
0
votes
2answers
2k views

Use mysql_query instead of $wpdb query

I have a custom table inside my wordpress database called test. What if i query this table using mysql_query() instead of using for example $wpdb->get_results() Will this affect my performance? Ty ...
0
votes
2answers
686 views

Have working sql query… trying to adjust it to use $wpdb

So I have this code that queries a custom plugin generated table in the wp database. It works perfectly as is. But I'm trying to adjust it to use $wpdb instead of the $con function I have set up. ...
0
votes
2answers
1k views

Wordpress(wpdb class) and mysql stored procedures

$query = "CALL .........."; $result = $wpdb->get_results($query); print_r($results); Is returning an empty array and $wpdb->query does not return anything, how do you run stored procedures from ...
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
2answers
362 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 ...
0
votes
2answers
61 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
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, ...
0
votes
1answer
31 views

$wpdb prepare issue with mysql DATE_FORMAT

Today, I have a issue in $wpdb. I used $result = $wpdb->get_var( $wpdb->prepare( "SELECT DATE_FORMAT(report_date, '%d-%m-%Y') FROM table WHERE report_id = %d", $report_id ) ); ...
0
votes
1answer
122 views

Use wpdb->prepare for `order by` column name

In my current plugin, I am picking up the order by column as user input. So I thought of using wpdb->prepare to escape it. $wpdb->get_results($wpdb->prepare("Select id from $wpdb->posts ...
0
votes
1answer
47 views

how to get db values without using an loop with wpdb->get_results()

So I want to return the data from 1 row from my custom DB table, but I dont want to use a loop as I only need the values once....so is there a way to do this? $results = ...
0
votes
1answer
75 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
240 views

insert image alongwith with custom data via a frontend form

I use wordpress as a cms. I wanted to insert custom data via a form from the frontend in my wordpress site and then echo it on a page somewhere. After learning from here and there I am able to put ...
0
votes
1answer
44 views

Create new database through static page code

I want to create a new table in current database of word press through create a static page. I write code for this as below, but there was no result. Why is that, and how can I get this right? ...
0
votes
1answer
57 views

How to stop $wpdb from prepending database name

When I run an UPDATE query using $wpdb, WP prepends the database name associated with the WP installation to whatever is passed in the table name argument. This isn't desirable as my app passes the ...
0
votes
1answer
93 views

$wpdb - joining shows no result

For one of my client's WP site, I'm making a plugin, where I'm using the db Query. I've two custom tables dedicated to the plugin: user_req — stores user chosen posts along with some custom ...
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 ...
0
votes
2answers
45 views

Mixing variables into an array when inserting values

I have a function that inserts a load of values into a database. Not a problem but I have a condition that changes the mysql statement. The problem is is the way wordpress constructs the statement, ...
0
votes
1answer
293 views

$wpdb->get_col and ORDER BY?

this is the query that returns the listing of a custom post type $apartments = $wpdb->get_col( " SELECT DISTINCT( post_id ) FROM $wpdb->postmeta ...
0
votes
1answer
113 views

Best practice to limit results in get_row()?

This is my query to check if a title exists (it's in a loop, therefore [$i]). $wpdb->get_row("SELECT * FROM wp_posts WHERE post_title = '" . $titles_arr[$i] . "'", 'ARRAY_A'); Anyway, I would ...
0
votes
2answers
148 views

query_post and wpdb returning different results

I am trying to get the woocommerce products by category.. When I query using the wpdb it gets the product correctly which exists in the backend products list. But when I query using the query_posts it ...
0
votes
2answers
2k views

$wpdb returns no results with SELECT query on custom post type, works on default post type

EDIT: Adding more background info. I've coded a plugin that adds a meta box to the post page. When the post is published, the plugin will generate a random ID for the post, and insert the random ID ...
0
votes
1answer
239 views

Custom SQL query ORDER BY term_order

I have custom taxonomy that list terms under "series" that contain posts that are also present in terms under "media_type" and where media_type is term_id 16. I want to order the list by the ...
0
votes
2answers
145 views

Really simple query giving error in SQL syntax

I'm sure this is a simple oversight but I cannot seem to narrow it down: global $wpdb; $tablename = $wpdb->prefix . "icrm_folders"; $sql = $wpdb->prepare( "SELECT * FROM %s", $tablename ); ...
0
votes
1answer
59 views

Custom $wpdb returns unexpected time based results

I am using the $wpdb class to do a custom SQL query but I am getting weird results. Basically this is what my SQL query is supposed to do Retrieve the titles of post_types 'question' only if they ...
0
votes
1answer
60 views

Specify strict 'order by' in WordPress query

I have a custom post type called Employees where an employee's name is the post_title of each post. I am trying to figure out how I would sort the post_title column by last name. So for instance, if ...
0
votes
2answers
300 views

Speed optimization of $wpdb->get_results

I'm using this code to generate all my custom field values from all posts for custom field named "autor". <?php $autor = $wpdb->get_results("SELECT meta_value AS autor FROM wp_posts, ...
0
votes
1answer
650 views

Creating an auto result search bar

I'm trying to create a search bar that will show me titles of posts when the user types into the text field. I'm completely new to this and I really don't know how to go about doing this. What would ...
0
votes
2answers
119 views

Build index page from custom fields

Im starting to delve deeper into Wordpress custom fields and wanting to replicate this page in Wordpress: http://www.clubsact.com.au/corporate/index.php So my site is not tightly structured to a ...
0
votes
1answer
276 views

Problem adding 'has-children' class to wp_nav_menu

According to a number of references online, I should be able to use the following function to add the class, has-children, to menu items that have children under them: function ...
0
votes
3answers
2k views

Custom $wpdb Query for Custom Post Type by Category

I am using the following code to output a list of items in my 'documents' Custom Post type by Year and Month. <ul> <?php $post_type = 'documents'; global $wpdb; /**/ $years = ...
0
votes
2answers
417 views

include wp-blog-header not working on MAMP

To clarify my question... My plugin is/was using AJAX to call the file pluginname/submit/pick.php My pluginname/pluginname.php contains the usual plugin header and wordpress automatically finds it. ...
0
votes
2answers
699 views

Ajax call in wordpress not working for subscriber user

All In my application there is notification system, when user click on that icon I want to make ajax call. The problem id it works fine for admin user (Debug : 200 ok), but not for subscriber user ...
0
votes
1answer
456 views

Best practice to import user base (subscribers) from one website to another?

I want to import users from a Wordpress installation to another. Same domain, but complete different websites. Website A (old, 700 users): running WP3.0 plain installation + BBPress 1.x Website B ...
0
votes
1answer
415 views

paginate_links on custom query in admin - 'sufficient permissions' error

I have created a page in my admin with this custom query: $rows = $wpdb->get_results("SELECT * FROM ej_feedback ORDER BY createdtime ASC"); I have made it successfully paginate as required in ...
0
votes
1answer
3k views

How does $wpdb handle COUNT(*)

I understand how to do simple queries and display results using $wpdb. This is my process: <?php $sql = 'select * from wp_votes;'; ?> <?php $votes = $wpdb->get_results($sql); ?> ...
0
votes
1answer
917 views

AJAX wp-mysql running too slow

I have made a function of ajax, which returns all the posts starting with a particular alphabet, suppose a user clicks on letter A, then all the posts starting with letter A will be displayed, any how ...
0
votes
1answer
1k views

Wordpress $wpdb get posts from category and sort by custom meta

I have a custom post type of 'events' which has a meta key 'event_date' Im using the following to retrieve those posts and arrange them by 'event_date' global $wpdb; $today = ...
0
votes
2answers
1k views

How to change a custom query into a standard loop?

I'm trying to modify how results are displayed in a post list that's currently controlled by the code below. However, it's not built in the WP_Query while ( $the_query->have_posts() ) : ...
0
votes
1answer
716 views

Wpdb->insert() doesn't insert new row after the last one

In JavaScript, I'm using an Ajax call and I'm sending an array of shops. Except for the last element in the array all the shops already exist in the DB. The last element is a new shop. The PHP code ...
0
votes
1answer
209 views

Compare transient data with a meta box value

So I'm not sure what would be the best way to go about this in terms of best practices and optimization. Scenario: I have query that parses an external XML feed and stores the data using the ...
0
votes
1answer
776 views

Ajax future single post query doesn't work when NOT logged in

I am having a problem with an ajax request for a single post, when the user is not logged in. The post is a calendar date and is in the future. the query works fine if I am logged into wordpress but ...
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
23 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 = ...