How to Get a List of Your WordPress Post and Page URL

post-urlGetting a list of your wordpress post or page URL can be done using simple PHP call method especially if you want to get it outside wordpress website. For example, you want to use the list to submit your URL to various resource during a SEO campaign you have already made. It also can be retrieved by using XML sitemap file then you can see the URL are sorted hierarchily. But for copy and paste work, it needs little more work to delete unnecessary line. And more work if you want only the slug. You have to edit them using a text editor such as Notepad++.

I have a simpler method using PHP files after reading WordPress Codex guide. and it doesn’t need to edit your list anymore. Just copy from your browser, and you’re done. If you want to get just the post URL, follow this step:

    1. Open Notepad++, you can get it here for free (open source).
    2. Copy and paste this code below:
1
2
3
4
5
6
7
8
9
10
<?
/* Short and sweet */
define('WP_USE_THEMES', false);
require('./wp-blog-header.php');
$args = array( 'numberposts' => 99999, 'orderby' => 'post_date', 'order' => 'DESC', 'post_type' => 'post', 'post_status' => 'publish', 'suppress_filters' => true );
$myposts = get_posts($args);
	foreach($myposts as $post){
		echo (the_permalink())."<br>";
}
?>
  1. Save it as PHP file and give a name for your file. For example, “getpost.php”.
  2. Upload to wordpress root path in your hosting, and then try call the PHP files in your browser. For example, “http://www.yourdomain.com/getpost.php”. You’ll see the result.

Get List of WordPress Post Slug

Within same method explained above, you also can get list of your post slugs. Use this code below instead:

1
2
3
4
5
6
7
8
9
10
<?
/* Short and sweet */
define('WP_USE_THEMES', false);
require('./wp-blog-header.php');
$args = array( 'numberposts' => 99999, 'orderby' => 'post_date', 'order' => 'DESC', 'post_type' => 'post', 'post_status' => 'publish', 'suppress_filters' => true );
$myposts = get_posts($args);
	foreach($myposts as $post){
		echo $post->post_name."<br>";
}
?>

And save it using different name. You can try “getpostslug.php”.

Get List of WordPress Page URL

Use this code below if you want to get all of your page URL.

1
2
3
4
5
6
7
8
9
10
<?
/* Short and sweet */
define('WP_USE_THEMES', false);
require('./wp-blog-header.php');
$args = array( 'sort_order' => 'ASC', 'sort_column' => 'post_title', 'number' => 99999, 'post_type' => 'page', 'post_status' => 'publish' );
$pages = get_pages($args); 
  foreach ( $pages as $page ) {
  	echo get_page_link( $page->ID )."<br>";
  }
?>

Save it and give a name such as “getpage.php”.

Get List of WordPress Page Slug

Here is code for displaying all of page slug.

1
2
3
4
5
6
7
8
9
10
<?
/* Short and sweet */
define('WP_USE_THEMES', false);
require('./wp-blog-header.php');
$args = array( 'sort_order' => 'ASC', 'sort_column' => 'post_title', 'number' => 99999, 'post_type' => 'page', 'post_status' => 'publish' );
$pages = get_pages($args); 
  foreach ( $pages as $page ) {
  	echo $page->post_name."<br>";
  }
?>

Save and give it unique different name.

I hope the code that already posted above an make your life easier when you need all of your post and page URL including slugs for your SEO project for example. If you don’t like to make your own files, then you can download these four files below and upload it in your hosting. Good luck!

Tired of Google Analytics? Try Piwik Free Web Analytics

piwik

Every webmaster and blogger know about Google Analytics. It has been used by lot of people to track their website traffic and activity. One of its key feature is tracking google adsense click. Yes, Google Analytics works nicely with Google Adsense service so you can monitor your adsense performance and [...]

Read the rest of this article »