将查询变量添加到Wordpress';页面链接';过滤器导致PHP致命错误

将查询变量添加到Wordpress';页面链接';过滤器导致PHP致命错误,php,wordpress,query-string,fatal-error,add-filter,Php,Wordpress,Query String,Fatal Error,Add Filter,我正在建立一个Wordpress站点,在这里我使用一个查询字符串来根据用户在站点中的旅程来设置页面颜色的主题 为了将当前颜色方案传递到下一页以增加连续性,我过滤页面链接并添加当前查询字符串(如果存在)。通过此代码: function append_query_string( $url, $post ) { if( !empty( $_GET['type'] ) ){ return add_query_arg( 'type', $_GET['type'], $url ); } el

我正在建立一个Wordpress站点,在这里我使用一个查询字符串来根据用户在站点中的旅程来设置页面颜色的主题

为了将当前颜色方案传递到下一页以增加连续性,我过滤页面链接并添加当前查询字符串(如果存在)。通过此代码:

function append_query_string( $url, $post ) {
  if( !empty( $_GET['type'] ) ){
    return add_query_arg( 'type', $_GET['type'], $url );
  } elseif ( is_page( array( 'sound', 'vfx' ) ) ) {
    return add_query_arg( 'type', get_the_slug(), $url );
  }
}
add_filter( 'page_link', 'append_query_string', 9, 2 );
add_filter( 'post_type_link', 'append_query_string', 10, 2 );
两个过滤器都工作正常。除了在一个页面上,它会导致内存问题。我已将其缩小到由“页面链接”过滤器引起的范围:

mod_fcgid: stderr: PHP Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 93 bytes)
我已经编辑了内存限制,不幸的是,这没有帮助,当它有足够的内存来避免内存错误时(512MB-我又把它放回去了),我仍然没有看到页面

我已经想不出是什么导致了这一切。我是第一个相信我的代码有问题的人,但是我不明白为什么除了一个页面外,这个网站在所有页面上都运行得很好

另外,该页面创建了视频幻灯片,如果我禁用“页面链接”过滤器,效果很好

您可以使用cookies:

add_action('init', 'myfunction');
function myfunction() {
    // You should sanitize 'type' before using it
    $type = $_GET['type'];
    if( !empty( $type ) ) {
        setcookie('current_color', $type, strtotime('+1 day'));     
    } elseif ( is_page( array( 'sound', 'vfx' ) ) ) {
        setcookie('current_color', get_the_slug(), strtotime('+1 day'));    
    }
}

然后您可以使用
$\u cookie['current\u color']

@Alan谢谢!我选择使用查询字符串选项的原因是允许用户共享带有正确颜色方案的URL。