0

I'm importin pictures via FTP and create custom recorss in mySQL via insert. I'm trying to make a cron job to regenerate thumbnails.

This is what i came up to.. but i doesnt work.

add_action( 'my_hook_regenerateimages', 'regenerateThumbnails' );

function regenerateThumbnails() {

//$images = $wpdb->get_results( "SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' AND post_mime_type LIKE 'image/%' AND DATE(´post_date´) > DATE_SUB(CURDATE(), INTERVAL 2 DAY)" );
//$images = $wpdb->get_results( "SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' AND post_mime_type LIKE 'image/%'");
$images = $wpdb->get_results( "SELECT ID FROM $wpdb->posts WHERE post_type = 'attachment' AND post_mime_type LIKE 'image/%' AND post_date > DATE_SUB(CURDATE(), INTERVAL 2 DAY)" );

foreach ( $images as $image ) {
    /*$id = $image->ID;
    $fullsizepath = get_attached_file( $id );

    if ( false === $fullsizepath || !file_exists($fullsizepath) )
        return;

    if ( wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $fullsizepath ) ) )
        return true;
    else
        return false;
    */
    $fullsizepath = get_attached_file( $image->ID );
    wp_update_attachment_metadata( $image->ID, wp_generate_attachment_metadata( $image->ID, $fullsizepath ) );      
}
}
  • No they are. I'm inserting them in database. Everything is OK, pictures are visible in products. Just this thumbnails that i cant figure out :(. – Kiki May 23 '19 at 4:12
  • Your code seems fine. But you do have global $wpdb; in the actual regenerateThumbnails() ? – Sally CJ May 23 '19 at 5:32
  • nope. so i guess thats the problem. i added "global $wpdb;" and now i think is ok. – Kiki May 23 '19 at 5:48
  • You could actually check the PHP/server error logs to see what happened, but I'm now quite sure it was because you did not load the $wpdb from the function. :) – Sally CJ May 23 '19 at 6:09
  • I was getting this error: PHP Fatal error: Maximum execution time of 30 seconds exceeded in /home/xxxxxx/domains/xxxxxx.si/private_html/wp-includes/class-wp-image-editor-imagick.php on line 358 so i added this line in .htaccess php_value max_execution_time 300 – Kiki May 23 '19 at 23:10

Your Answer

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

Browse other questions tagged or ask your own question.