WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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,

share|improve this question
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

Your Answer


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.