Created
January 3, 2017 12:33
-
-
Save mostafasoufi/fd9fc306a59d0182b0b39418b8af156d to your computer and use it in GitHub Desktop.
Get first post link in Wordpress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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