I am trying to make a simple plugin that will output the URL and title of a post. It should look like this:
http://mysite.com/test-2/{Test 2}
However when I use the code that I posted below, it prints as follows:
http://mysite.com/test-2/Test 2
{}
I can’t figure out why. I’ve tried to escape them, separating each bracket into a string and combining them, but nothing seems to work.
Heres the code
function P2S_menu(){
echo '<h1>This is a Test</h1>';
$query = new WP_Query($query_string . '&orderby=title&order=asc&posts_per_page=-1');
while($query->have_posts()){
$query->the_post();
$url = the_permalink();
$keyword = the_title();
Print('<p>' . $url . '{' . $keyword . '}' . '</p><br>');
}
echo 'Done';
}
The functions
the_permalink()
andthe_title()
print their results by default. Useget_permalink()
andget_the_title()
instead: