I’m using the following code to access my wordpress from another page:
<?php
include $_SERVER['DOCUMENT_ROOT'].'/wp-load.php';
global $wpdb;
$image_ID = $wpdb->get_var("SELECT post_id FROM $wpdb->postmeta WHERE meta_value = '6036' AND meta_key = '_wp_attached_file'");
//regenerate thumbnail
$fullsizepath = get_attached_file( $image_ID );
$metadata = wp_generate_attachment_metadata( $image_ID, $fullsizepath );
wp_update_attachment_metadata( $image_ID, $metadata );
?>
I get the following error:
Fatal error: Call to undefined function wp_generate_attachment_metadata()
The $wpdb query works fine and get_attached_file, too. The only problem is that I can’t use wp_generate_attachment_metadata.
Does anybody know why that happens? Did I forget to include something?
EDIT: I just realized I just forgot to include( ABSPATH . 'wp-admin/includes/image.php' );
You need to include wp-blog-header.php to set up the wordpress environment.