Wordpress - Using functions outside of wordpress

admin

Administrator
Staff member
I'm using the following code to access my wordpress from another page:

Code:
    <?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:

Code:
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 <a href="http://codex.wordpress.org/Function_Reference/wp_generate_attachment_metadata" rel="nofollow">wp_generate_attachment_metadata</a>.

Does anybody know why that happens? Did I forget to include something?

<strong>EDIT:</strong> I just realized I just forgot to
Code:
include( ABSPATH . 'wp-admin/includes/image.php' );