您最终可以在$sql中添加ID,这样在foreach中使用get\\u permalink函数就更容易了:
<?php
global $wpdb;
$sql = "SELECT ID, post_title, meta_value
FROM $wpdb->posts a
JOIN $wpdb->postmeta b ON a.ID = b.post_id
WHERE a.post_type = \'page\'
AND a.post_status = \'publish\'
AND b.meta_key = \'_wp_page_template\'
ORDER BY a.post_title ASC
";
$results = $wpdb->get_results( $sql );
if( !empty( $results ) ) {
echo \'<ul>\';
foreach ( $results as $result ) {
echo \'<li><a href="\'.get_permalink($result->ID).\'">\'. $result->post_title . \': \' . $result->meta_value. \'</a></li>\';}
echo \'</ul>\';
}
?>