Skip to content

Instantly share code, notes, and snippets.

@mostafasoufi
Created January 3, 2017 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mostafasoufi/fd9fc306a59d0182b0b39418b8af156d to your computer and use it in GitHub Desktop.
Save mostafasoufi/fd9fc306a59d0182b0b39418b8af156d to your computer and use it in GitHub Desktop.
Get first post link in Wordpress
<?php
function get_first_post_link() {
global $wpdb, $table_prefix;
$result = $wpdb->get_row("select * from {$table_prefix}posts where post_type = 'post' and post_status = 'publish' ORDER BY `{$table_prefix}posts`.`ID` ASC LIMIT 1");
if($result) {
return get_permalink( $result->ID );
}
}
echo get_first_post_link();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment