0

I have this function in my functions.php

<?php 
if ( !wp_next_scheduled('re-post2') ) {
   wp_schedule_event( time(), 'hourly', 'rep-post2' );
}

function repostads() {
    global $wpdb;
 $querystr = "
    UPDATE $wpdb->posts 
    INNER JOIN $wpdb->repost
    ON $wpdb->posts.ID = $wpdb->repost.post_id
    AND $wpdb->repost.DIA_FINAL >= NOW()
    AND $wpdb->repost.ESTADO = 'OK'
    SET $wpdb->posts.post_date = NOW()
     ";
}
add_action ( 're-post2', 'repostads' );
     ?>

I try to insert the query code in a sample page, and works fine, but when I insert in functions.php, it doesn't do nothing.

  • 3
    Please follow up on your questions. Take a look at the help center to see how this site works. – kaiser Oct 10 '14 at 8:13
1

And what do you think it should do?

Either you posted here only part of your code or it can't do anything that makes sense. The only thing this function does is assigning a value to a variable. This SQL query is never executed, because you don't execute it anywhere in your code.

I guess you want to do something like this:

if ( !wp_next_scheduled('re-post2') ) {
   wp_schedule_event( time(), 'hourly', 'rep-post2' );
}

function repostads() {
    global $wpdb;
    $querystr = "UPDATE $wpdb->posts 
    INNER JOIN $wpdb->repost
    ON $wpdb->posts.ID = $wpdb->repost.post_id
    AND $wpdb->repost.DIA_FINAL >= NOW()
    AND $wpdb->repost.ESTADO = 'OK'
    SET $wpdb->posts.post_date = NOW()";
    $wpbd->query( $querystr );
}
add_action ( 're-post2', 'repostads' );

I'm assuming here that your SQL query is correct.

0

You've got a typo in your $hook that might be the issue -- 're-post2' becomes 'rep-post2' in the wp_schedule_event() call.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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