I would like to get the list of all URLs from a wordpress installation. Nevertheless, I Don't want the full post titles in the permalink but I would like the shortlinks instead. I would like to get the following in the same fashion:
/?p=123
/?p=124
/?p=125
/?p=126
I would like to get the list of all URLs from a wordpress installation. Nevertheless, I Don't want the full post titles in the permalink but I would like the shortlinks instead. I would like to get the following in the same fashion:
https://example/?p=123
https://example/?p=124
https://example/?p=125
https://example/?p=126
Share
Improve this question
edited Jun 5, 2019 at 4:42
Nicolas Guérinet
asked Jun 4, 2019 at 19:28
Nicolas GuérinetNicolas Guérinet
2642 gold badges5 silver badges12 bronze badges
2 Answers
Reset to default 1You can get this from the guid
column in the posts
table of your database.
Couple ways to go here, my friend.
Plugin: All-in-SEO (https://wordpress/plugins/all-in-one-seo-pack/). Generates a sitemap.xml that should be mighty useful for your needs.
Code: If you need an array of permalinks to work with later, I'd recommend you use The Loop (https://codex.wordpress/The_Loop) to loop through all your posts, pages, etc. and feed the_permalink (https://codex.wordpress/Function_Reference/the_permalink) in an array.
Something like this:
<?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();
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745436799a4627644.html
评论列表(0条)