我使用以下代码从另一个页面访问我的 WordPress:
<?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 );
?>
我收到以下错误:
Fatal error: Call to undefined function wp_generate_attachment_metadata()
$wpdb 查询和 get_attached_file 都可以正常工作。唯一的问题是我无法使用wp_generate_attachment_metadata http://codex.wordpress.org/Function_Reference/wp_generate_attachment_metadata.
有谁知道为什么会发生这种情况?我是否忘记添加一些内容?
EDIT:我刚刚意识到我只是忘记了include( ABSPATH . 'wp-admin/includes/image.php' );
您需要包含 wp-blog-header.php 来设置 wordpress 环境。
<?php
require('blog/wp-blog-header.php');
$args = array( 'numberposts' => 5, 'post_status'=>"publish", 'post_type'=>"post", 'orderby'=>"post_date");
$postslist = get_posts( $args );
foreach ($postslist as $post) : setup_postdata($post); ?>
<ul class="headline">
<li class="title">
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li>
</ul>
<?php endforeach; ?>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)