我正在努力将我本地wordpress网站的博客文章导出为pdf文件。 换句话说,将我单独编写的所有帖子合并到一个文件中,例如pdf,doc或任何其他格式......
我自己试图通过创建一个自定义插件来做到这一点,但是我没有成功检索帖子,所以我尝试使用标准的php直接使用wordpress类,并将文件放在根文件夹下本地网站不在插件文件夹中,这是我的代码:
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "scienceted";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$querystr = "
SELECT wp_posts.post_title as Title, wp_posts.post_date as DATE,
GROUP_CONCAT(wp_terms.name) AS TAGS, wp_posts.post_content as CONTENT FROM wp_terms
INNER JOIN wp_term_taxonomy ON wp_terms.term_id = wp_term_taxonomy.term_id
INNER JOIN wp_term_relationships ON wp_term_taxonomy.term_taxonomy_id = wp_term_relationships.term_taxonomy_id
INNER JOIN wp_posts ON wp_posts.ID = wp_term_relationships.object_id
WHERE post_author = 0 AND post_type LIKE 'post' AND post_status LIKE 'publish' GROUP BY wp_posts.ID order by post_date\G
";
$result = $conn->query($querystr);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "id: ";
}
} else {
echo "0 results";
}
$conn->close();
第23行是:if ($result->num_rows > 0) {
如果此步骤正确完成,那么我可以按类别对帖子进行分组。