wpdb

$wpdb not working in file of WordPress plugin

I am working in WordPress plugin. I create a custom form where user add values and then click on submit button. When user click on submit button its redirect to custom process file, where i write queries for inserting and updating data. I my process.php file, first i call global $wpdb, but my insert and update queries not working so…
Read more

Escaping a MySQL query containing variables with PHP

I’m running the following code on a WordPress website to query the database: $entries = $wpdb->get_results( “SELECT `id`, `lead_id`, `form_id`, `field_number`, `value` FROM `wp_rg_lead_detail` WHERE `value` = “John” OR `value` = “Smith” OR `value` = “22101” ORDER BY `lead_id`” ); I’d like to replace the hard coded values with pre-defined variables. I’ve attempted to do so using the following code:…
Read more

Does WP query update accept variables being built into it?

Below is the code I’ve come up with. The var_dump code shows the correct string to be inserted but the last query dump at the end shows an incomplete query with no variable being passed it seems. So I’m not sure if this is a WP specific quirk or what could be the issue here? Any ideas? $numItems = count($changeorderVar);…
Read more

How to insert a single row to a WordPress database table?

Intro: I have a function that handles a contact form variables in my website. user enters name, email and text. function.php gets variables using javascript. I get more information on the user on the way – like IP, Country, UTM tags if any, ect. Then I added a code part that saves the variables respectively on a SQL table. I…
Read more

WordPress prepared LIKE query [on hold]

I’m trying to use a prepared LIKE query within WordPress, but it doesn’t seem to be working. I’ve followed the codex for the syntax. public function userByJobId($id){ global $wpdb; $result = $wpdb->get_row($wpdb->prepare( “SELECT * FROM use_users WHERE use_job_id LIKE = d%;”, ‘%’ . $wpdb->esc_like((int)$id)) . ‘%’); if(!empty($result)){ return $result; } return false; } Calling the method like so: $userid =…
Read more

wpdb->get_row – Get the number of totalResults

this is my query $wpdb->get_row(“SELECT * FROM `wp_posts` INNER JOIN wp_term_relationships ON wp_term_relationships.object_id = ID AND wp_term_relationships.term_taxonomy_id = 1 WHERE `post_title` REGEXP ‘^A’ LIMIT $offset , $posts_per_page”, ‘ARRAY_N’); The results are Ok but i dont get the totalPost count echo $wpdb->found_posts; // empty What i am doing wrong? Source: wpdb

$wpdb->get_results not accepting variable in query

I have the following in my functions.php file. I’m trying to return a metavalue(s) for a custom post. add_action( ‘transition_post_status’, ‘a_new_post’, 10, 3 ); function a_new_post( $new_status, $old_status, $post ) { if ( ‘publish’ !== $new_status or ‘publish’ === $old_status ) return; if ( ‘post’ == $post->jobman_job ) return; // all of the above is just to trigger the below…
Read more

MySQL update wp_posts based on wp_meta value?

I’m creating a custom plug-in for my WordPress site that will run a query. The plugin will run via WordPress’ wp_schedule_event function to run daily. This query will act upon the engine post type with a custom field named wpcf-engine-days-to-go. Currently, my code is not working (see below) Goal I want to update the post_status to ‘draft’ when a custom…
Read more

Querying and Filtering WP custom post type joined with meta

i just tried out to speed up my queries in WordPress. At the moment I have a custom post type called ‘schulungstermin’ (course date in english). With the advanced custom fields plugin I hooked in there some custom fields for begin date, end date etc. I now want to query these post type based on a training relationship field without…
Read more