简体   繁体   English

如何通过PHP代码段在WordPress中使用$ _get

[英]How to Use $_get in WordPress by PHP snippets

I'm using WordPress and a plugin named "PHP snippets" to add my own coding in a WordPress page. 我正在使用WordPress和一个名为“ PHP代码段”的插件在WordPress页面中添加自己的编码。

So, here is my code that I have added: 因此,这是我添加的代码:

<script>
jQuery(document).ready(function(){
    showjob();
});
    function showjob() {    
    var intrest=document.getElementById("intrest").value; 
        jQuery.ajax({
            method: 'GET',
            url: 'jobsloader.php',
            data: {
                intrest: intrest,
              <?php 
                 if ($_GET['type']=="need") //the problem starts here... No matter what is the value of type in url it is always echoing feed... even if there is no type in url it is echoing feed...
                 {
                   echo "type: 'need'";
                 }
                 else
                 {
                   echo "type: 'feed'";
                 }
              ?>
            },
            success: function(data) 
            {
                document.getElementById("addcontainer").innerHTML = data;
            }
        });
    }
</script>

What am I doing wrong? 我究竟做错了什么?

if you want more details, please ask in comments! 如果您需要更多详细信息,请在评论中提问!

example: URL I was using was like this ' http://www.abcd.in/bs/?type=need ' 例如:我使用的URL就是这样' http://www.abcd.in/bs/?type=need '

moreover I want 3 cases: 此外,我要3种情况:

  1. if there is type 如果有类型

  2. if type=need 如果类型=需要

  3. if type=feed 如果type = feed

嗯,我不知道你的插件,但在用GET请求来传递数据正确的方法是: http://www.abcd.in/bs.php?type=need或者实现URL重写,然后: http://www.abcd.in/bs/need

Wordpress supresses GET variables for security purposes, so you must register them in either a plugin or your theme's functions.php file : 为了安全起见,WordPress禁止使用GET变量,因此您必须在插件或主题的functions.php文件中注册它们:

function custom_query_vars_filter($vars) {
 $vars[] .= 'need';
 $vars[] .= 'feed';
 return $vars;
}
add_filter( 'query_vars', 'custom_query_vars_filter' );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM