Forums

Pass address line variables to my page (2 posts)

  1. eazi.it
    Member
    Posted 4 months ago #

    I have written a page that will (when fully enabled) allow me to show dynamic content.

    This content is dependant and a variable (side) that I want to pass from the address line

    i.e. http://www.arufc.com/?page_id=718&side=2nd%20XV

    this opens the page but does not pass the variable side.

    Do I need to globally register the variable somewhere?

  2. Dagon Design
    Member
    Posted 4 months ago #

    Yes. When I first looked into doing this, it was near impossible to find information on it, but here is a method I use.

    Add this to a plugin, or your theme's functions.php file:

    function add_query_vars ( $vars ) {
    	$vars[] = "side";
    	return $vars;
    }
    
    add_filter('query_vars', 'add_query_vars');

    That will 'tell' WP to look for a new query var called 'side'

    Then in your code, you can use this function to get the value passed:

    get_query_var("side");

    Now if you want to integrate that data into permalinks, it gets a good bit tricker.

Reply

You must log in to post.

About this Topic

Tags

No tags yet.