【发布时间】:2016-10-04 22:07:06
【问题描述】:
我编写了一些代码,用于在我的 wordpress 网站的帖子表中提取附件。
第一个函数会下拉结果,但我无法将其写入文本文件。
文件的创建很好,我没有收到任何错误。代码正在运行,我只是没有收到日志。我想知道它准备移动哪些文件。
这是我的插件中有问题的功能
function getPostsToMove($baseurl){
$baseurl = $baseurl.'/%/%/%.%';
$myfile = fopen("/websites/site.dev/wp-content/uploads/newfile.txt", "w") or die("Unable to open file!");
global $wpdb ;
return $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE `guid` not
like '$baseurl' and `post_type` = 'attachment' ORDER BY post_date DESC LIMIT 1000");
fwrite($myfile, $baseurl);
fclose($myfile);
}
我错过了什么?
编辑-我的顺序错了。下面这些是对的。但显然我没有从我的回报中获取数据。我需要把它变成一个数组吗?
新代码
function getPostsToMove($baseurl){
$baseurl = $baseurl.'/%/%/%.%';
$myfile = fopen("/websites/site.dev/wp-content/uploads/newfile.txt", "w") or die("Unable to open file!");
fwrite($myfile, $output);
fclose($myfile);
global $wpdb;
$output = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE `guid` not
like '$baseurl' and `post_type` = 'attachment' ORDER BY post_date DESC LIMIT 1000");
return $output;
}
【问题讨论】:
-
return表示返回...return之后没有执行任何操作 -
是的,试试在函数末尾加上
return。 -
这只是收集要移动的文件的第一个函数,如何在查询发生之前写入和关闭文件?
-
为了记录,我试过了,只是为了确定。它没有写任何东西。但插件有效。
-
我的意思是,也许这是正确的顺序,但我没有获取返回的数据。我不知道。我以前没有这样做过。