Write a mysql query to update a single database entry

I am running a function to update the status of a custom post type to 'pending' when the user role is changed to 'subscriber'. At the same time I need to update an entry in the database to correspond.

The table to update is from the Events Manager plugin. (See the attached image)

We need to set the DB table cell value to 0 to match the post update. (0 is pending, 1 is published, -1 is trash)

Here's the function:

//We need to set events that were published by expired users to 'pending'

add_action( 'set_user_role', 'draft_demoted_user_events', 10, 2 );

function draft_demoted_user_events( $demoted_author_id, $role ) {

if( ('subscriber' == $role) || ('s2member_level0' == $role) && 'publish' == get_post_status( $p->ID) ) {

$args = array( 'numberposts' => -1,

'author' => $demoted_author_id,

'post_type' => 'event', );

$demoted_author_posts = get_posts( $args );

foreach( $demoted_author_posts as $p ) {

$my_post = array(

'ID' => $p->ID,

'post_status' => 'pending', );

wp_update_post( $my_post );

//Now do the database table update

//UPDATE `database_name`.`wp_em_events` SET `event_status` = '0' WHERE `wp_em_events`.`event_id` = ID;




Here is the function that Events Manager uses to update the status. The same thing that I need to update.


* Change the status of the event. This will save to the Database too.

* @param int $status

* @param boolean $set_post_status

* @return string


function set_status($status, $set_post_status = false){

global $wpdb;

if($status === null){



//if the post is trash, don't untrash it!

$wpdb->update( $wpdb->posts, array( 'post_status' => 'draft' ), array( 'ID' => $this->post_id ) );


$this->post_status = 'draft'; //set post status in this instance

}elseif( $status == -1 ){ //trashed post

$set_status = -1;


$wpdb->update( $wpdb->posts, array( 'post_status' => $this->post_status ), array( 'ID' => $this->post_id ) );


$this->post_status = 'trash'; //set post status in this instance


$set_status = $status ? 1:0;

$post_status = $set_status ? 'publish':'pending';


if($this->post_status == 'pending' && empty($this->post_name)){

$this->post_name = sanitize_title($this->post_title);


$wpdb->update( $wpdb->posts, array( 'post_status' => $post_status, 'post_name' => $this->post_name ), array( 'ID' => $this->post_id ) );


$this->post_status = $post_status;



$result = $wpdb->query( $wpdb->prepare("UPDATE ".EM_EVENTS_TABLE." SET event_status=$set_status, event_slug=%s WHERE event_id=%d", array($this->post_name, $this->event_id)) );

$this->get_status(); //reload status

return apply_filters('em_event_set_status', $result !== false, $status, $this);


Skills: MySQL, PHP, WordPress

See more: wordpress php code editor, magento price stock update mysql query, change event manager wordpress calendar colors, change css event manager wordpress, xml update mysql query php, portfolio wordpress php code, generate sitemap wordpress php code, change file size limit php wordpress, form onchange update mysql query, wordpress users profile php, php event calendar wordpress, rss wordpress php code, script run mysql query write results csv file, invisible yahoo messenger users detecting php code, update mysql query java, import php board users wordpress, update mysql database csv file, write query update mysql, write javascript function mysql query, upload file update mysql database, mysql query remote database, update mysql database using email, quickly update mysql database, write mysql query, video plugin wordpress php code

About the Employer:
( 9 reviews ) Hotchkiss, United States

Project ID: #11538830

Awarded to:


Hello, I'm an experienced wordpress developer and I'm familiar with Events Manager plugin as well and so I can make the required function within a few hours after you accept my bid. Regards, Tamas

$30 USD in 0 days
(218 Reviews)

25 freelancers are bidding on average $37 for this job


Dear sir, I am good for Wordpress, php, mysql, html, css,....etc so i can help you finish it. Please check my profile and give me this chance. Thank you and waiting here

$35 USD in 0 days
(252 Reviews)

Hi, I am wordpress,PHP programmer having 5 years of experience. I am very good in wordpress,php,mysql,joomla. Recently done these projects [login to view URL] Please award me the project.

$35 USD in 1 day
(349 Reviews)

Dear Client, Thank you for allowing us to place a bid on your project. We have very good hands on experience in working with the LAMP stack especially with PHP frameworks such as Smarty, Codeigniter, Yii, Zend, More

$50 USD in 1 day
(171 Reviews)
$30 USD in 1 day
(85 Reviews)

Hello, This is not copy/paste message. I read your requirements. I am interested for this job. I have expertise in Wordpress, Laravel, Magento, AngularJS, Ruby on Rails, Core PHP etc. technologies and can work on More

$25 USD in 1 day
(30 Reviews)

Hello Sir, I am pleased to inform you that we have 8+ years experienced developers in Mysql. we can surely update single database entry. I would be happy to work with you on this project. We want to build a long More

$35 USD in 1 day
(24 Reviews)

Hello Project Owner, We have gone through with your initial requirements and analyzed the our skills best suits with your project requirements. We have 7 year of experience in web development and mobile develo More

$25 USD in 1 day
(52 Reviews)

Hello, Your job post just caught my [login to view URL] mentioned in your requirement are some thing that we work day and night on,enhancing our skills as we keep finishing project. Word Press Exp : 7 Years,makes Av More

$30 USD in 1 day
(31 Reviews)

I have more than 5 years of professional and practical experience in MySQL and database development. I have more than 1800 answers in Stackoverflow(Q&A Site) [login to view URL] More

$30 USD in 0 days
(33 Reviews)

Hello I am interested for this project. Provide me link of your website so i can have a look over there. I am a Web Expert come Web Coder. I have worked as Web Design & concept Consultant With Expertise of Code More

$150 USD in 2 days
(73 Reviews)

Hello sir. I am a wordpress expert with more than 3 years of experience. Let's discuss more. Regards

$10 USD in 1 day
(64 Reviews)

Hello, I have ranking in top 5000 on and I hope it will give you an idea about my work quality and dedication to work. You will be safe while working with me. I have dedicated in house team for Wo More

$111 USD in 3 days
(9 Reviews)

Hi, 1. do you want a single sql script (query) that update all the entries in the table wp_em_events related to a author_id? ex. UPDATE with JOIN? 2. do you want a trigger script? sql script (UPDATE)? php code? More

$35 USD in 1 day
(14 Reviews)

5 Reasons why you should hire me for your custom website and Application Development. 1. Available 24/7 upon your request 2. Delivery on-time with 100% satisfaction 3. Always think beyond boundaries and provide user fr More

$20 USD in 6 days
(20 Reviews)

Expert in MySQL and WordPress. Please let me know if we can work together Thanks Kaja

$10 USD in 1 day
(11 Reviews)

A proposal has not yet been provided

$30 USD in 3 days
(4 Reviews)

I am database expert having experience of 3 years.I will complete your work as per requirements and deliver it on time.

$30 USD in 1 day
(4 Reviews)

Hello I am Software Engineer and expert in database design and development so you can consider me for this Project Thanks I will wait for your quick response

$25 USD in 1 day
(6 Reviews)

Dear Project Owner, My name is Vadim, I've worked as a wordpress developer for 2 years for a website development company in Ukraine. I am new at and I am looking for long term partnership. I believe tha More

$20 USD in 1 day
(4 Reviews)

Greetings, I am ready to start doing it right [login to view URL] can check out my works in my portfolio. Contact me! with regards, Nick.

$30 USD in 3 days
(5 Reviews)