I have the following jQuery code:-

jQuery('.fancymember').on('click', function() {
    var member = jQuery(this).parent('div').parent('div').find('.test').val();
    var dataString = 'member='+ member;
      type: "POST",
      url: "http://website.dev/wp-content/themes/website/template-about.php",
      data: dataString,
      dataType: 'text',
      //    alert(member);


I want to pass the value 'member' to use in a Wordpress page template, I am trying to retrieve the value as follows:-

<?php $testing = $_POST['member']; ?>

But when I do:-

<?php var_dump($testing); ?>

$testing is NULL, any ideas what I am doing wrong?

I've tried to pass it to the page name as well but that didn't work (url: "get-to-know-us",)

Okay just checked in firebug console and I get the following error:-

Fatal error: Call to undefined function get_header() in /Applications/AMPPS/www/distinct.dev /wp-content/themes/distinct/template-about.php on line 6

However, using url: "get-to-know-us", I can see it has posted the value:-

member 71 Source member=71

So I still don't understand why I can't display this in PHP?

  • If you open your browser's developer tools and trigger the request - you should be able to view the request sent to the ajax script and make sure that the data is being passed along correctly. Feb 8, 2016 at 16:22
  • @AricWatson - Updated the question
    – nsilva
    Feb 8, 2016 at 16:36
  • you can't load template files directly, WordPress is not loaded in that context.
    – Milo
    Feb 8, 2016 at 18:10
  • What exactly are you trying to accomplish here? I think you need to rethink your approach because from the limited info you've provided it's not making a whole lot of sense why you you want to pass the var back to php
    – Joey Yax
    Feb 8, 2016 at 18:58
  • @JoeyYax, passing a var back to php like this would be helpful in the case of 3rd party site widgets where you need to get information from the site.
    – Ben
    Feb 17, 2018 at 4:57


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.