WordPress获取文章别名(slug)

获取当前文章别名

/**
 * WordPress获取文章别名(slug)
 * http://www.liuweb.com/20180815000710.html
 */
function get_the_slug() {
    global $post;
    $post_data = get_post($post->ID, ARRAY_A);
    $slug = $post_data['post_name'];
    return $slug; 
}

获取所有文章别名

/**
 * WordPress获取文章别名(slug)
 * http://www.liuweb.com/20180815000710.html
 */
function get_all_slug(){
    global $wpdb;
    $sql = "SELECT id,post_title,post_name FROM `wp_posts` WHERE post_type = 'post' AND post_status = 'publish'";
    $res = $wpdb->get_results($sql,ARRAY_A);
    foreach($res as $v){
        //相应处理
        var_dump($v);
    }
}