• Hi, i have this sql query:

    mysql_query("SELECT distinct ID, post_title, guid, wp_posts.ID FROM wp_posts WHERE wp_posts.post_status = 'publish' AND wp_posts.post_type = 'post' order by wp_posts.ID desc");

    then when i try to link the post, the link is in the format https://localhost/?p=1. I’d like the link as the permalink in the blog settings (https://localhost/2011/11/06/hello-world/.

    I read in the forum to use get_permalink () but i don’t know how to use it, i get an error!

Viewing 2 replies - 1 through 2 (of 2 total)
  • Using mysql does not allow you to use WordPress functions without extra work (and additional overhead).

    Is it possible for you to use WP_Query instead of calling mysql directly?

    This will do your query exactly, the “wordpress way”. You can still access the row variables via the $post variable inside the loop (ie. $post->guid).

    $query = new WP_Query( 'post_status=publish&orderby=ID&order=DESC' );
    while ( $query->have_posts() ): $query->the_post();
        echo get_permalink();
    endwhile;
    wp_reset_postdata();
    Thread Starter antonio nardelli

    (@antonio-nardelli)

    Thank you h0tw1r3, i found a semi-solution using first you rewrited query, then i use sql.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Sql query – how get the permalink from the guid?’ is closed to new replies.