doutong4088 2015-03-30 08:33
浏览 433
已采纳

Wordpress - get_permalink在%postname%permalink设置中返回page_id而不是slug

So, I have wordpress site with http://example.com/%postname%/ in permalink setting.

I want to echo get_permalink(), which showing http://example.com/?page_id=xx result

but when I did echo get_permalink(), it's return http://example.com/some-slug/. I know it's not an error because the permalink setting is %postname%.

I want to use it like this :
echo '<a href="'. get_permalink() .'&get_weather='. $weather .'"></a>';

to make link result like this :
<a href="http://example.com/?page_id=1&get_weather=rain"></a>

instead of this result:
<a href="http://example.com/some-slug/&get_weather=rain"></a>

So, is it possible to get result of http://example.com/?page_id=xx while echo-ing get_permalink() with %postname% (or other permalink setting option) as the permalink setting? please explain how

Thanks.

  • 写回答

1条回答 默认 最新

  • dsghpgmay31938863 2015-03-30 08:48
    关注

    Just create the url manually

    <?php 
      $url = add_query_arg( array('page_id' => get_the_ID(), 'get_weather' => 'rain'), home_url('/') );
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?