2016-09-20 47 views
1

我在Wordpress中有4個帖子。在這些帖子中,他們可以添加自定義字段的鏈接。我得到這個代碼如何獲取the_ID()的鏈接;

   <?php 

        $args = array('post_type' => 'post'); 

        $loop = new WP_Query($args); 
        while ($loop->have_posts()) : $loop->the_post(); 
         the_ID(); 
        endwhile; 

        $other_page = 1330; // variable 
        the_field('bloglink', $other_page); // show link 

       ?> 

輸出爲:104013301196827,#LINK (我爲other_page $爲例)

我qeustion是:如何可以使用這些ID的做一個鏈接?

任何幫助表示讚賞,

回答

1

get_the_ID() - 檢索在WordPress循環當前項目的ID。

<?php 

    $args = array('post_type' => 'post'); 

    $loop = new WP_Query($args); 
    while ($loop->have_posts()) : $loop->the_post(); 
     the_ID(); 
     the_field('bloglink', get_the_ID()); // show link 
    endwhile; 

?> 
+0

謝謝你的幫助! – di477