Wordpress: How can I add url GET parameter to my main menu items

前端 未结 4 413
醉话见心
醉话见心 2021-01-12 17:25

I\'m trying to add a URL GET parameter to one of my main menu items in Wordpress(but I don\'t know how to). So, my approach was to detect a click event on the menu item, the

4条回答
  •  醉酒成梦
    2021-01-12 18:21

    The problem is that you are attempting to pass a boolean value in your Ajax call with the variable homeclick. GET requests simply use text because the data is passed thru the URL, so if you are wanting a logical/boolean type you can use either "true" and "false" in text or perhaps 0 and 1. Also you have a syntax error, see below.

    Try the following:

    In you ajax call, fix the syntax as well as set homeclick to "true" as follows: data: ({ homeclick: 'true' }),.

    And in your php, change the if condition for variable $homeclick as follows: $homeclick == 'true'.

    You may want to consider using a POST method if you want to utilize a boolean.

提交回复
热议问题