Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.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
在loop-wordpress插件中插入一些帖子_Wordpress - Fatal编程技术网

在loop-wordpress插件中插入一些帖子

在loop-wordpress插件中插入一些帖子,wordpress,Wordpress,我写了一个插件,可以读取csv文件并创建新产品。当我只创建一个产品,但在Insert()中添加while时,插件可以工作。插件不工作。我想先创建所有产品。也许这和添加动作有关。。。请帮忙 define( 'PLUGIN_DIR', dirname(__FILE__).'/' ); function CreateProduct($line) { $data = explode('";"', $line); define(POST_NAME, $data[2]);

我写了一个插件,可以读取csv文件并创建新产品。当我只创建一个产品,但在
Insert()
中添加
while
时,插件可以工作。插件不工作。我想先创建所有产品。也许这和添加动作有关。。。请帮忙

define( 'PLUGIN_DIR', dirname(__FILE__).'/' );

function CreateProduct($line) {    
    $data = explode('";"', $line);  
    define(POST_NAME, $data[2]);
    define(cena_netto_pw, $data[5]);

    $post = get_page_by_title( POST_NAME, 'OBJECT', 'product'  );
    $product_ID = $post->ID;
    $post_data = get_post($product_ID);

    function hbt_create_post() {
        $my_post = array(
          'post_title'    => POST_NAME,
          'post_content'  => '',
          'post_status'   => 'publish',
          'post_author'   => 1,
          'post_type'     =>'product'
        );

        $product_ID = wp_insert_post( $my_post );
    }

    if(!isset($post))
        hbt_create_post();
    return $error_obj;
}

function Import() {
    $file = PLUGIN_DIR.'test.csv';
    $open = fopen($file, 'r');
    while (!feof($open)) {

        $line = fgets($open);
        CreateProduct($line);

    }
    fclose($open); 
}

add_action('admin_init', 'Import' ); 

?>
While循环码

while (!feof($open)) { $line = fgets($open); CreateProduct($line); }
这个代码不起作用。当只有

$line = fgets($open); CreateProduct($line);
试一试

反而

fgets($open)

使用while循环显示代码:while(!feof($open)){$line=fgets($open);CreateProduct($line);}此代码不起作用。当只有$line=fgets($open)时,它工作;CreateProduct($line);请使用
txt
文件而不是csv进行测试。结果如何?
fgets($open)