I’m trying to list the post titles using a regular wp_query, just to add the permalink to the a href of the items, this is the code i’m using:
<?php $the_query = new WP_Query( 'post_type=artworks_post' );
// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post();
echo '<a rel="' .the_permalink(). '" href="' .the_permalink. ' ">';
the_title();
echo '</a>';
endwhile;
// Reset Post Data
wp_reset_postdata();
?>
The problem is that the code is not working, it just returns the a href with the word “permalink” but no the link itself.
What i’m doing wrong here?
Try to use get_permalink instead of the_permalink. Function the_permalink is printing the permalink itself (http://codex.wordpress.org/Function_Reference/the_permalink), but function get_permalink returning the permalink string (http://codex.wordpress.org/Function_Reference/get_permalink).
Anyway just a suggestion, use printf instead of echo. such as,
As requested, I add the example using echo instead of printf