如何获取所有页面URL的列表,包括它们的快捷链接ID?

时间:2019-06-04 作者:Nicolas Guérinet

我想从wordpress安装中获取所有URL的列表。尽管如此,我不想在permalink中看到完整的帖子标题,但我希望看到短链接。我想以同样的方式获得以下内容:

https://example.com/?p=123
https://example.com/?p=124
https://example.com/?p=125
https://example.com/?p=126

2 个回复
最合适的回答,由SO网友:MikeNGarrett 整理而成

你可以从guid 中的列posts 数据库的表。

List of guids from database, eg http://wordpress.test/?p=1

SO网友:Jakob Smith

我的朋友,有两条路要走。

Plugin:全方位搜索引擎优化(https://wordpress.org/plugins/all-in-one-seo-pack/). 生成网站地图。xml应该对您的需求非常有用。

Code:如果以后需要使用永久链接数组,我建议您使用循环(https://codex.wordpress.org/The_Loop) 循环浏览所有帖子、页面等,并向\\u permalink提供(https://codex.wordpress.org/Function_Reference/the_permalink) 在数组中。

类似这样:

<?php
    // Not copy and paste safe, please read
    // This sets up what we want to fetch from the database
    // All the posts, pages, and any other custom post types
    // Setting \'posts_per_page\' to -1 give you all the matches in the db
     $args = array(\'post_type\' => array( \'post\', \'page\', \'any-other-custom-post-type\'), \'posts_per_page\' => -1 );

     // Go get what we want
     $WP_objects_I_will_loop_through = new WP_Query($args);

     //If there are any objects in the db that match our search...
     if ($WP_objects_I_will_loop_through->have_posts()):
        //loop through them and...
         while ($WP_objects_I_will_loop_through->have_posts()):
            //...Start with the first one, and then the next and....
             $WP_objects_I_will_loop_through->the_post();
             //...get the right post object each time through the loop
             global $post;
            // Create an array to fill with URL\'s and...
             $my_array_filled_with_urls = [];
             // Pop them in one at a time
             $my_array_filled_with_urls[] = get_permalink($post->ID);

         endwhile;
     endif;
     // Keeps you safe if you use this somewhere near another loop
     wp_reset_query();

相关推荐

Problem with permalinks

我已经更改了类别的基本名称,现在它是“博客”,工作正常。但当我通过/blog/%category%/%postname%/更改结构时。显示404。如果我删除结构中的blog,它会再次工作,但我想使用blog word。问题出在哪里?非常感谢。