Support » Developing with WordPress » Fetch URL parameter

  • I have an URL http://127.0.0.1/wordpressbosta/team/?team=teamOne.

    I would like to fetch team value teamOne in functions.php like below.

    
    function get_data()
    {
    	echo json_encode($_GET['team']);	
    	die;
    }
    
    add_action('wp_ajax_get_data', 'get_data'); 
    add_action('wp_ajax_nopriv_get_data', 'get_data'); 
    

    But it is not working.

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

    (@bcworkz)

    Try an URL query string like this:
    ?team=teamOne&action=get_data
    WP Ajax always requires an “action” parameter be passed.

    You’re trying to fetch data in an ajax callback so you must send an ajax GET request

    so instead of this http://127.0.0.1/wordpressbosta/team/?team=teamOne

    use this http://127.0.0.1/wordpressbosta/wp-admin/admin-ajax.php?action=get_data&team=teamOne

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Fetch URL parameter’ is closed to new replies.