In Progress

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){

$set_status='NULL';

if($set_post_status){

//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;

if($set_post_status){

$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

}else{

$set_status = $status ? 1:0;

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

if($set_post_status){

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;

}

$this->get_previous_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:
( 8 reviews ) Hotchkiss, United States

Project ID: #11538830

Awarded to:

herpay

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)
6.1

26 freelancers are bidding on average $37 for this job

miennh

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
(250 Reviews)
6.9
sat12

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

$35 USD in 1 day
(335 Reviews)
6.7
ownmyserver

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
(166 Reviews)
6.2
phpfreelancer86

Hello Sir, I've reviewed your requirement and I'm ready to work with you. I will provide quality work as well full support for any query. I'm giving you trust for good quality work. I have almost 7+ years of expe More

$30 USD in 0 days
(115 Reviews)
5.9
Dckumawat

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
(50 Reviews)
5.5
rainstreamweb

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
(29 Reviews)
5.3
avinsoln

Hello, Your job post just caught my [url removed, login to view] 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
(29 Reviews)
5.2
mahmoudgamal008

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) [url removed, login to view] More

$30 USD in 0 days
(33 Reviews)
5.2
modisharray

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
(72 Reviews)
5.9
$30 USD in 1 day
(59 Reviews)
5.4
OrangeTechsol

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
(19 Reviews)
5.1
Dilipjaipur

Hello, I have ranking in top 5000 on [url removed, login to view] 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)
4.7
parveen2505

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

$10 USD in 1 day
(62 Reviews)
4.8
pinaliv

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
(19 Reviews)
4.9
angnut

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)
4.2
johnosullivan

A proposal has not yet been provided

$30 USD in 3 days
(4 Reviews)
3.1
mjkaja

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

$10 USD in 1 day
(10 Reviews)
2.8
rafaelnadal

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)
3.6
fb570f4ddfe2f26

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 [url removed, login to view] and I am looking for long term partnership. I believe tha More

$20 USD in 1 day
(4 Reviews)
2.2
kolyfedoriv

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

$30 USD in 3 days
(5 Reviews)
2.1