Php 如何在wordpress站点上设置cookie?

Php 如何在wordpress站点上设置cookie?,php,wordpress,cookies,Php,Wordpress,Cookies,我在wordpress网站上设置和读取cookie时遇到问题 以下是我正在做的: 1.通过js id发送到php ajax.js jQuery.post("/wp-content/themes/mytheme/ajax.php", {post_id: post_id}, function(data){ }); ajax.php setcookie('myids', $_COOKIE['myids'].$_POST['post_id'], time()+3600*24*100, '/');

我在wordpress网站上设置和读取cookie时遇到问题

以下是我正在做的:

1.通过js id发送到php

ajax.js

jQuery.post("/wp-content/themes/mytheme/ajax.php", {post_id: post_id}, function(data){

});
ajax.php

setcookie('myids', $_COOKIE['myids'].$_POST['post_id'], time()+3600*24*100, '/');
2.当我在/wp content/themes/mytheme/index.php中读到那个cookie(echo$_cookie['myid'])时

我得到了我设置的值,这没关系,但当我试图在/wp content/themes/mytheme/ajax.php中读取cookie时,我没有得到cookie


我做错了什么?

解决方案:将ajax.php放在root(/ajax.php)中,然后它就工作了。

您还没有发布您正在做什么(代码方面)来读取cookie,因此我们无法开始说明您做错了什么。我已经改变了问题,/wp content/themes/mytheme/ajax.php看到的
$\u cookie
的内容是什么?