我想我要么誤解了WP Codex對wp_safe_redirect()函數(shù)的定義,要么我是個笨蛋,沒有正確使用它。(我什至不知道WP有這樣的功能,但是每天都在學(xué)習(xí)對吧?)因此,在某些情況下,我有一個新實(shí)例,WP_Query它遍歷特定的帖子類型,然后根據(jù) ACF 字段 meta_key 提取單個結(jié)果。我只是想將用戶重定向到第一個也是唯一找到的結(jié)果。這是我的嘗試;$args = array( 'post_type' => array( 'locale' ), 'post_status' => array( 'published' ), 'nopaging' => true, 'posts_per_page' => '1', 'meta_key' => 'postal_town', 'meta_value' => $postal_town_result);$postcodeSearch = new WP_Query( $args );if($postcodeSearch->have_posts()) : while($postcodeSearch->have_posts()) : $postcodeSearch->the_post(); $perma_url = the_permalink(); wp_safe_redirect( $perma_url ); // just prints the url? exit; endwhile; else: echo 'Oops, there are no posts.'endif;任何建議將不勝感激。
wp_safe_redirect(); 不是重定向,它只是打印給定的變量?
哆啦的時光機(jī)
2022-07-29 10:26:50
