title: Wordpress get_permalink() PHP Link not working for external links in posts
body: <p>Using wordpress and editing some PHP code in my child theme and have run into an issue with a sidebar widget for popular posts.</p>
  
  <p>Each blog post in wordpress that is popular accurately shows up in the popular posts sidebar, and clicking the story title it will go to the single story page <em>on my blog</em>.</p>
  
  <p>The correct code in this widget to link to my own blog posts in widgets.php is:</p>
  
  <pre><code>    if ( $popular_posts-&gt;have_posts() ) {
          $result .= '&lt;div class="post-popular"&gt;&lt;ul class="list"&gt;';
          while ( $popular_posts-&gt;have_posts() ) {
              $popular_posts-&gt;the_post();
              $comments_text = sprintf( _n( '%1$s comment', '%1$s comments', get_comments_number(), APP_TD ), get_comments_number() );
              $result .= '&lt;li&gt;&lt;a href="' . get_permalink() . '"&gt;' . get_the_title() . '&lt;/a&gt; - ' . $comments_text . '&lt;/li&gt;';
          }
          $result .= '&lt;/ul&gt;&lt;/div&gt;';
      }
  </code></pre>
  
  <p>Since this is a sidebar widget of popular articles, I would like the sidebar clicks to go directly to the <strong>external site</strong> for each article, and not my blog posts.</p>
  
  <p>Within each blog post is a direct <strong>external</strong> link to the actual article for each.
  This is tagged for each post as the following code <strong>article_out_url</strong></p>
  
  <p>I tried the following code edit for get_permalink() to make it get_permalink($url) to go to each external such such as:</p>
  
  <pre><code>$url = get_post_meta( $post-&gt;ID, 'article_out_url', true );
  $result .= '&lt;li&gt;&lt;a href="' . get_permalink($url) . '"&gt;' . get_the_title() . '&lt;/a&gt; - ' . $comments_text . '&lt;/li&gt;';
  </code></pre>
  
  <p>Such as the following:</p>
  
  <pre><code>    if ( $popular_posts-&gt;have_posts() ) {
          $result .= '&lt;div class="post-popular"&gt;&lt;ul class="list"&gt;';
          while ( $popular_posts-&gt;have_posts() ) {
              $url = get_post_meta( $post-&gt;ID, 'article_out_url', true );
              $popular_posts-&gt;the_post();
              $comments_text = sprintf( _n( '%1$s comment', '%1$s comments', get_comments_number(), APP_TD ), get_comments_number() );
              $result .= '&lt;li&gt;&lt;a href="' . get_permalink($url) . '"&gt;' . get_the_title() . '&lt;/a&gt; - ' . $comments_text . '&lt;/li&gt;';
          }
          $result .= '&lt;/ul&gt;&lt;/div&gt;';
      }
  </code></pre>
  
  <p>However, this didn't work. Instead of going to the external link, clicking on the link simply went to my root domain only. Not even the individual post on the topic.</p>
  
  <p>I'm stumped. Any ideas with how I can get each article link to go to the the article_out_url URL for each post? Thanks.</p>