Php wp_safe_redirect();isn';t重定向,它只打印给定的变量?
我想我要么是误解了Php wp_safe_redirect();isn';t重定向,它只打印给定的变量?,php,wordpress,Php,Wordpress,我想我要么是误解了wp\u safe\u redirect()函数的功能,要么是因为我是一个口香糖,没有正确使用它。(我甚至不知道WP有这样的功能,但嘿,每天都在学习,对吗?) 因此,在某些场景中,我有一个新的WP\u Query实例,它循环遍历特定的post类型,然后根据ACF字段meta\u键提取单个结果。我只想将用户重定向到第一个也是唯一找到的结果 这是我的尝试 $args = array( 'post_type' => array( 'locale
wp\u safe\u redirect()
函数的功能,要么是因为我是一个口香糖,没有正确使用它。(我甚至不知道WP有这样的功能,但嘿,每天都在学习,对吗?)
因此,在某些场景中,我有一个新的WP\u Query
实例,它循环遍历特定的post类型,然后根据ACF字段meta\u键提取单个结果。我只想将用户重定向到第一个也是唯一找到的结果
这是我的尝试强>
$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;
如有任何建议,我们将不胜感激。来自WordPress:
永久链接
显示当前帖子的永久链接
因此,这实际上显示了它,并且在输出之后,报头重定向失败,因为已经发送了报头
您希望返回永久链接而不是显示它:
$perma_url = get_permalink();
wp_safe_redirect( $perma_url );
exit;
此外,通过以下或WordPress的等效设置,您将看到:
error_reporting(E_ALL);
ini_set('display_errors', '1');