Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Is it possible to move a post to an another category if post_meta field is 0 ?
I'm building a reverse order vote, every post have by default 10 votes and after a user vote, removes one vote by updating the post_meta, now i try to move the post to an another category if the votes field is 0 or 2 days old.

I have found a solution here that moves a post to an another category if is a past date from this in the database.
It runs every hour to do the check

if (!wp_next_scheduled('sfn_expire_hook')){
    wp_schedule_event( time(), 'hourly', 'sfn_expire_hook');
}

add_action( 'sfn_expire_hook', 'sfn_show_expire');
function sfn_show_expire(){
    global $wpdb;
    $server_time = date('mdy');
    $result = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_type = 'post' AND post_status = 'publish'");
    if( !empty($result)) foreach ($result as $a){
        $show_time = get_the_time('mdy', $a->ID);
        if ( $server_time > $show_time ){
           $my_post = array();
           $my_post['ID'] = $a->ID;
           $my_post['post_status'] = 'draft';
           wp_update_post( $my_post );
        }
    } // end foreach
}

can someone help me to extend this to check for 2 days old posts and if post_meta "votes" is "0" also?

thanks a lot,
Philip

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

When you remove vote check for your condition, then if needed:

  1. fetch categories with wp_get_object_terms() (low level func, you can specify to fetch names or ids only since you don't need full objects for this)
  2. modify array (remove category you don't need, add the one you do)
  3. set categories with wp_set_post_categories() (it will overwrite all categories so those you remove from array will be gone)
share|improve this answer
    
Thanks @Rarst, i have found a solution that i think can do the trick, but i can't find how to do it...any help? –  Philip Jan 23 '11 at 8:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.