【问题标题】:Prevent WordPress to remove my variables added in my url (custom post type)阻止 WordPress 删除我在我的网址中添加的变量(自定义帖子类型)
【发布时间】:2016-08-19 08:29:39
【问题描述】:


您知道为什么当我在“自定义帖子类型”(单数)页面上而不是在标准页面上时 WordPress 会删除变量吗?

这是我在循环中创建 URL 的方法。

<a href="<?php echo esc_url( add_query_arg( 'p', $url, the_permalink() ) ); ?>">See more</a>

链接生成正确,但是当我点击“?p=value”时被删除...

提前致谢! :)

【问题讨论】:

    标签: php wordpress url custom-post-type urlvariables


    【解决方案1】:

    问题是您正在使用“the_permalink()”来输出值本身。

    您需要使用get_the_permalink() 函数。

    您的新代码将如下所示:

    <a href="<?php echo esc_url( add_query_arg( 'a', $url, get_the_permalink() ) ); ?>">See more</a>
    

    更新:

    另外,您正试图在您的网址中保留?p=xxx。 WordPress 将p 作为帖子 id 变量,因此它使用它并使用永久链接重写规则来重定向并从 url 中删除它。

    如果您使用 ?p= 以外的任何内容,您将保留查询变量,请尝试 ?a=something 例如

    【讨论】:

    • 不幸的是,这并不能解决我的问题。 (不过越来越好了,所以谢谢) 供参考,如果我在url栏中手动添加“?p=value”,这部分会被自动删除。
    • 可以分享链接吗?
    • 这是因为 wordpress 使用“p”来显示帖子,它会保留任何其他变量,试试 ?a=something
    • 不客气 :) 我也将此添加到答案中。请将答案标记为正确,如果有用,请点赞:)
    猜你喜欢
    • 2012-08-27
    • 2018-02-23
    • 2020-06-11
    • 2019-02-22
    • 2015-02-16
    • 2011-07-01
    • 1970-01-01
    • 2012-04-10
    • 1970-01-01
    相关资源
    最近更新 更多