Forums

Pass address line variables to my page (3 posts)

  1. eazi.it
    Member
    Posted 2 years 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 2 years 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.

  3. converting2wp
    Member
    Posted 1 year ago #

    Is there any way to register a user variable as a global (and so be able to access it from other pages WITHOUT passing it on the query string)?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.