• I am making a little widget to show post in the “events” category by the “event_date” custom field, using this Date Field plugin.

    The posts are selected properly, but when I use “echo the_permalink()” in line to make my link, it jumps to the front of the line before everything else.

    This is the code from my widget function:

    echo '<ul>';
    
    	query_posts( 'category_name=events&meta_key=date_value&orderby=meta_value&meta_compare=>=&meta_value=' . time() . '&order=ASC' );
    
    	while (have_posts()) : the_post();
    		$post_id = get_the_ID();
    		$link = '<li><a href="';
    		$link .= the_permalink();
    		$link .= '">';
    		echo $link;
    		echo the_title().' - ';
    		echo date("F jS, Y", get_post_meta($post_id, 'date_value', true)).'</a></li>';
     	endwhile;
    
    		echo '</ul>';

    and it generates the following HTML:

    <ul>https://cdri.org/2010/05/native-bee-workshop/<li><a href="">Native Bee Workshop - May 31st, 2010</a></li></ul>

    I tried using the $link variable to force the_permalink() into the right place after the usual loop syntax didn’t work.

    Any suggestions would be greatly appreciated!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Try using get_the_permalink() instead.

    Thread Starter chrisruggia

    (@chrisruggia)

    Thanks!! I tried it, editing that line to:

    $link .= get_the_permalink();

    and got the following:

    Fatal error: Call to undefined function get_the_permalink() in /homepages/40/d319439206/htdocs/wordpress-site/wp-content/plugins/cdri-eventlist.php on line 29

    Any thoughts?

    If it helps, the widget is in the sidebar, which is called after the main loop runs, and before the footer.

    Thank you again for responding.

    Sorry – my bad! Try get_permalink()

    Thread Starter chrisruggia

    (@chrisruggia)

    Now, that did work!

    Is there a listing in the codex somewhere showing the breakdown of loop functions like the_permalink() and get_permalink() and when each should be used?

    THANKS!

    Thread Starter chrisruggia

    (@chrisruggia)

    I looked a bit and found the Template Tags list, which did tell me what options are available.

    I’m still a little shaky on the difference between the_permalink() and get_permalink(), though. Could you possibly explain, or direct me to a resource that will?

    Thanks again – you’ve been a huge help.

    the_permalink returns & displays the permalink. get_permalink just returns the permalink for use in a function or script.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘the_permalink() is out of place in query_posts() widget’ is closed to new replies.