Title: mk_button with query string
Last modified: September 1, 2016

---

# mk_button with query string

 *  [markhuynhmelbourne](https://wordpress.org/support/users/markhuynhmelbourne/)
 * (@markhuynhmelbourne)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/mk_button-with-query-string/)
 * Hi all
 * I am not much of a coder but want to have a way to create [mk_button] with url
   link to include current query string.
 * Something like this:
 * example.com/?house=1
    [mk_button url=”/ref/<?house=1>”]
 * Does anyone know a simple method to update button reference to include current
   url query string?
 * Thanks in advance!

Viewing 6 replies - 1 through 6 (of 6 total)

 *  [Eric](https://wordpress.org/support/users/shamai/)
 * (@shamai)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/mk_button-with-query-string/#post-7626612)
 * so you want the current query string from the url in the address and what do 
   you want to do with it exactly?
 * when you show a button on the page it should grab the house parameter?
 *  Thread Starter [markhuynhmelbourne](https://wordpress.org/support/users/markhuynhmelbourne/)
 * (@markhuynhmelbourne)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/mk_button-with-query-string/#post-7626657)
 * Hi Shamai
 * Yes you are correct, the button should great the all of the query string from
   the URL. Eg:
 * URL
    example.com/?house=2 Button [mk_button url=”/ref/?house=2″]
 * URL
    example.com/?site=australia Button [mk_button url=”/ref/?site=australia”]
 * This allows for me to pass these parameters to a form which will then choose 
   the correct display.
 *  [Eric](https://wordpress.org/support/users/shamai/)
 * (@shamai)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/mk_button-with-query-string/#post-7626660)
 * Are you using a form plugin or did you make the form yourself?
 * Are you trying to populate fields in a form?
 *  Thread Starter [markhuynhmelbourne](https://wordpress.org/support/users/markhuynhmelbourne/)
 * (@markhuynhmelbourne)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/mk_button-with-query-string/#post-7626667)
 * Hi Shamai
 * Yes, I am using Gravity Forms plugin. The form allows for capturing of data from
   the query string and to populate certain fields.
 * Users come in from external sites and I differentiate this by proving link something
   like this:
 * External site 1
    example.com/?house=2
 * External site 2
    example.com/?house=5
 * There is a button on my landing page which I want to direct url to example.com/
   ref and include the original query string:
    example.com/?house=2 example.com/?
   house=5
 * The form can then capture parameter house and update the field as required.
 * This helps me to track on the form where the lead is coming from.
 * Thanks again for looking into this.
 *  [Jacob Peattie](https://wordpress.org/support/users/jakept/)
 * (@jakept)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/mk_button-with-query-string/#post-7626672)
 * I think you’d be better of capturing the query string in a Cookie, on first visit.
   And then using the `gform_field_value_` filter in Gravity Forms to populate the
   form.
 * So you’d have something like
 *     ```
       function prefix_remember_query_string() {
       	if ( isset( $_GET['query_string_to_remember'] ) ) {
       		setcookie( 'cookie_for_remembering', $_GET['query_string_to_remember'], 30 * DAYS_IN_SECONDS );
       	}
       }
       add_action( 'init', 'prefix_remember_query_string' );
   
       function prefix_populate_form_field( $value ) {
       	if ( isset( $_COOKIE['cookie_for_remembering'] ) ) {
       		$value = esc_attr( $_COOKIE['cookie_for_remembering'] );
       	}
       	return $value;
       }
       add_filter( 'gform_field_value_your_parameter', 'my_custom_population_function' );
       ```
   
 * Where `gform_field_value_your_parameter` is `gform_field_value_` then the parameter
   name as given in Gravity Forms. Read more about that here: [https://www.gravityhelp.com/documentation/article/using-dynamic-population/](https://www.gravityhelp.com/documentation/article/using-dynamic-population/)
 *  Thread Starter [markhuynhmelbourne](https://wordpress.org/support/users/markhuynhmelbourne/)
 * (@markhuynhmelbourne)
 * [9 years, 9 months ago](https://wordpress.org/support/topic/mk_button-with-query-string/#post-7626674)
 * Thanks Jacob. I will give your solution a go.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘mk_button with query string’ is closed to new replies.

## Tags

 * [button](https://wordpress.org/support/topic-tag/button/)
 * [Query String](https://wordpress.org/support/topic-tag/query-string/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 6 replies
 * 3 participants
 * Last reply from: [markhuynhmelbourne](https://wordpress.org/support/users/markhuynhmelbourne/)
 * Last activity: [9 years, 9 months ago](https://wordpress.org/support/topic/mk_button-with-query-string/#post-7626674)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
