我想选择一个对象,并且该对象ID必须保存在cookie会话中。我如何在wordpress中做到这一点?
到目前为止,我得到了这个add_action( 'init', 'setting_my_first_cookie' );
function setting_my_first_cookie() {
setcookie( $SeasonId, 30 * DAYS_IN_SECONDS, COOKIEPATH, COOKIE_DOMAIN );
}
if(!isset($_COOKIE[$SeasonId])) {
echo "The cookie: '" . $SeasonId . "' is not set.";
} else {
echo "The cookie '" . $SeasonId . "' is set.";
echo "Cookie is: " . $_COOKIE[$SeasonId];
}
unset( $_COOKIE[$SeasonId] );
setcookie( $SeasonId, '', time() - ( 15 * 60 ) );
wp_redirect( home_url(), 302 );
exit;
并且像这样调用对象
echo "<td><a href='?SeasonId=".$Season->Id."'>";
echo "$Season->DateFrom - $Season->DateTo";
echo "</a></td>";
我做错了什么?还是有其他解决方案
感谢
答案 0 :(得分:0)
这是调用季节列表
的功能function Season () {
echo "<ul class='accordion' data-accordion data-allow-all-closed='true'>";
echo "<li id='' class='accordion-item' data-accordion-item>";
echo "<a href='#' class='accordion-title' style='background-color:#3db7e4; padding: 1rem; color:white;'><h6><strong>Maak een keuze</strong></h6></a>";
echo "<div class='hover accordion-content' data-tab-content>";
echo "<table class='hover'>";
echo "<tbody>";
/**
* Get list of seasons.
*/
$Seasons = WaterpoloAPI::call("Seasons", "getSeasons");
$SeasonId = "";
foreach($Seasons as $Season) {
echo "<tr>";
echo "<td><a href='?SeasonId=".$Season->Id."'>";
echo "$Season->DateFrom - $Season->DateTo";
echo "</a></td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
echo "</div>";
echo "</li>";
echo "</ul>";
}