Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何检索以前访问过的WordPress的帖子ID和自定义字段_Php_Wordpress - Fatal编程技术网

Php 如何检索以前访问过的WordPress的帖子ID和自定义字段

Php 如何检索以前访问过的WordPress的帖子ID和自定义字段,php,wordpress,Php,Wordpress,我有几个帖子会重定向到感谢页面。 在我的感谢页面中,我想检索以前或上次访问的post\u id,以便检索post\u id的自定义字段值,以使我的条件生效 $postid = get_the_ID(); $tags= get_field('product_tags', $postid); if(tags == 'action' && !is_user_logged_in()) { echo 'Not For you'; } else { echo

我有几个帖子会重定向到感谢页面。 在我的感谢页面中,我想检索以前或上次访问的
post\u id
,以便检索
post\u id
的自定义字段值,以使我的条件生效

$postid = get_the_ID();
$tags= get_field('product_tags', $postid);

if(tags == 'action'  &&  !is_user_logged_in()) {    

        echo 'Not For you';
}

else {
echo 'Welcome';
}
结果是:


您已经访问了“自定义字段”下的“上次访问的帖子标题”

我们有一些选项可供选择

1) 您可以使用$\u服务器['HTTP\u REFERER']查找帖子id。您可以通过上一页的slug找到post_id,您可以从$_服务器['HTTP_REFERER']获得它

2) 当重定向到感谢页面时。您可以在查询字符串中包含帖子id。大概

wp_重定向(site_url('Thankyu?id='.$post->id)); 退出

或者,如果您使用javascript进行重定向,则可以获得类似的结果

希望能有帮助