Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress-使用Wordpress之外的函数_Php_Wordpress - Fatal编程技术网

Php Wordpress-使用Wordpress之外的函数

Php Wordpress-使用Wordpress之外的函数,php,wordpress,Php,Wordpress,我正在使用以下代码从另一个页面访问我的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

我正在使用以下代码从另一个页面访问我的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 );

    ?>
$wpdb查询工作正常,也可以获取附加的文件。唯一的问题是我不能使用

有人知道为什么会这样吗?我忘了写点什么了吗


编辑:我刚刚意识到我忘记了
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; ?> 

    <?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; ?>