wpdb

WordPress: Passing variable into $wpdb returns NULL

I am having a really strange issue with my code. I am trying to grab a row from the database using $wpdb-get_row, but it doesn’t work when I’m grabbing the value from the CSV. In my below code, when I pass $unqiue_id into the query, it returns NULL. $unqiue_id comes from the CSV and is properly echoing the correct numbers….
Read more

Bulk duplicating post_meta only inserts meta of first post in loop correctly into Database (WordPress with CRED)

I am using the CRED plugin’s API to perform certain actions upon submitting a certain CRED form. It’s basically not important but the issue is related to how the CRED plugin reads the Data after the Form is submitted. When I submit a CRED Form, I duplicate the post which is currently Edited by CRED, and also all it’s child…
Read more

Retrieving row from table based on logged in user

I have a draggable div with position being saved to database. But when I try to query the database, it isn’t echoing last position. Is there something I am missing here? Any input is greatly appreciated. UPDATE: I have rewritten the code below and all is now working properly global $wpdb; $user_exists = $wpdb->get_row($wpdb->prepare(“SELECT * FROM coords WHERE user_id =…
Read more

Retriving Post Data from WordPress Database

I am learning plugin development recently. I am trying to develope a test plugin which will show a table of lists of Drafts post. To achieve this I am running below query in my plugin. But I can see the Table is empty. <table class=”widefat”> <thead> <tr> <th>Post Title</th> <th>Post ID</th> </tr> </thead> <tfoot> <tr> <th>Post Title</th> <th>Post ID</th> </tr>…
Read more

WordPress oop wpdb in class

I am new in OOP PHP and I am trying to use $wpdb (WORDPRESS) object in some of my custom classes but have no idea how to do it. Every time I try to implement basic operations with $wpdb results in fail. I need some basic stuff like get_results(),…. So how to do something like this: global $wpdb; $my_custom_table =…
Read more

SQL query and $wpdb prepare

I’ve started digging into $wpdb to query stuff from the database, I have the following query: global $wpdb; $sql = $wpdb->get_var( $wpdb->prepare( ” COUNT(*) FROM $wpdb->posts WHERE post_type = ‘products’ AND post_status = ‘publish’ AND post_date >= DATE_SUB(CURDATE(), INTERVAL DAYOFMONTH(CURDATE())-1 DAY) ” ) ); echo $sql; This returns the number 3 just as wanted but also returns the following error:…
Read more

$wpdb returns duplicate posts

I have created a shortcode which shows the posts which were created after the user last logged in. The shortcode is working perfectly fine, but I am not sure why but I am getting 7 duplicate posts. So like for test I created a post named as “Sample Article”, and when I echo out the title of the post, I…
Read more