• Hi,

    I am writing a plugin and considering using shortcodes to accomplish this, information is going to be passed from page to page. In doing so a variable is going to be passed and I want to take that variable and use it for the shortcode.

    So the first page would be

    https://mysite/comps/

    under that would be a whole lot of links like

    comp1
    comp2

    comp1 would link to https://mysite/comps/comp/1

    etc

    I want to then grab the variable of comp=1 and pass that to the shortcode so the shortcode would take you to the comp page and the rewrite_endpoint(‘comp’, …)

    would pick up that the rest are variables and values. And I can have a short code of something like

    [myshortcode_comp comp=$_GET[“comp”]]

    Not sure exactly whether this is possible but if it is can anyone possibly help out here?

    Cheers
    Dan

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    If there were a value for $_GET["comp"] you could use directly in your shortcode callback, no need to pass it as a shortcode attribute. If you are passing the value in the initial request as part of a permalink structure, there’s a good chance $_GET will have no values at all. For $_GET to be assigned values, the URL must have parameters of the form /index.php?comp=1. If you were to rewrite the permalink back into such a form, then once again $_GET should have values.

    If your rewrite rules are correctly parsing the permalink, you should be able to get the values you need from the global $wp_query as one of the query vars.

    There remains a slight uncertainty in my mind about what will and will not work. I suggest setting up a test scenario and see just what is available in your callback. I am sure you can get the value, just not quite sure where it will be.

    Thread Starter dannymh

    (@dannymh)

    Thank you.
    I solved this in the manner you suggested, just grabbed it and processed it as part of the shortcode

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Using $_GET variables as a shortcode attribute’ is closed to new replies.