最新消息:

wordpress导出所有文章标题和链接

WordPress 大步 889浏览 0评论
第一种:
将下面的报错为export.php放到 wordpress网站根目录
  1. <?php
  2. include "wp-load.php";
  3. $posts = new WP_Query('post_type=any&posts_per_page=-1&post_status=publish');
  4. $posts = $posts->posts;
  5. /*
  6. global $wpdb;
  7. $posts = $wpdb->get_results("
  8. SELECT ID,post_type,post_title
  9. FROM {$wpdb->posts}
  10. WHERE post_status<>'auto-draft' AND post_type NOT IN ('revision','nav_menu_item')
  11. ");
  12. */
  13. header('Content-type:text/plain');
  14. foreach($posts as $post) {
  15. switch ($post->post_type) {
  16. case 'revision':
  17. case 'nav_menu_item':
  18. break;
  19. case 'page':
  20. $permalink = get_page_link($post->ID);
  21. break;
  22. case 'post':
  23. $permalink = get_permalink($post->ID);
  24. break;
  25. case 'attachment':
  26. $permalink = get_attachment_link($post->ID);
  27. break;
  28. default:
  29. $permalink = get_post_permalink($post->ID);
  30. break;
  31. }
  32. echo "\n{$post->post_type}\t{$permalink}\t{$post->post_title}";
  33. }
  34. >
第二种:
  1. SELECT wpp.post_title,
  2. wpp.guid,
  3. wpp.post_date,
  4. CONCAT
  5. (
  6. wpo_su.option_value,
  7. REPLACE
  8. (
  9. REPLACE
  10. (
  11. REPLACE
  12. (
  13. REPLACE
  14. (
  15. wpo.option_value,
  16. '%year%',
  17. date_format(wpp.post_date,'%Y')
  18. ),
  19. '%monthnum%',
  20. date_format(wpp.post_date, '%m')
  21. ),
  22. '%day%',
  23. date_format(wpp.post_date, '%d')
  24. ),
  25. '%postname%',
  26. wpp.post_name
  27. )
  28. ) AS permalink
  29. FROM wp_posts wpp
  30. JOIN wp_options wpo
  31. ON wpo.option_name = 'permalink_structure'
  32. AND wpo.blog_id = 0
  33. JOIN wp_options wpo_su
  34. ON wpo_su.option_name = 'siteurl'
  35. AND wpo_su.blog_id = wpo.blog_id
  36. WHERE wpp.post_type = 'post'
  37. AND wpp.post_status = 'publish'
  38. ORDER BY wpp.post_date DESC
第三种:

I also wanted this solution and thanks @MikeSchinkle for the original
solution. I did use this to export those links in plain text to excel
and then build my redirect list.

But then I found that I also wanted a solution with live, active links.

So I used the wp_query using the post type "any" and created a page template with a search form included with the following query (customize to fit your theme as you see fit). Note I had to set the posts_per_page at -1 to return unlimited results. This returns results as: "Title - Permalink"

 

 

 

Hope that helps others.

 

来自为知笔记(Wiz)

转载请注明:大步's Blog » wordpress导出所有文章标题和链接

SiteMap