how to get permalink using sql

I am not sure why you are using a custom query and not get_posts() or WP_Query as you should.

Anyway, you need to get the post ID …

$query ="SELECT     wp_posts.post_title AS title , 
                    wp_posts.post_content AS content,
                    wp_posts.post_date AS blogdate ,
                    wp_posts.ID AS ID

And then just pass this ID to get_permalink():

get_permalink( $post->ID );

Similar for the title attribute:

the_title_attribute( [ 'post' => $post->ID ] );

Leave a Comment