1

I am trying to pass URL parameters to a Wordpress template page:

www.mysite.com/my_wp_page_template/?city=Anytown&state=ST

Based on some forum examples I have added the following code to the functions.php:

add_filter('query_vars', 'parameter_queryvars' );
function parameter_queryvars( $qvars )
{
  $qvars[] = 'City';
  $qvars[] .= 'State';
  return $qvars;
}

And, I am trying to extract the variables in a PHP file that is included in a WP page using:

report_for_city.php
<?php
$strCity = $_GET["City"]; 
$strState = $_GET["State"];
$strCityState = $strCity . ' ' . $strState;
?>
<p>This page contains the report for <?php $strCityState ?>.</p>

But, the variable is not getting inserted in the output HTML. The HTML is being inserted into the WP page, so the PHP template is getting invoked from the WP page using the insert-php plugin:

[insert_php]include('wp-content/php/report_for_city.php');[/insert_php]

What am I doing wrong? How can this be fixed?

1 Answer 1

2

The PHP code was missing echo in:

php $strCityState

The following code corrected the problem:

php echo $strCityState

Is there an easier way to output the value than this?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.