Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Passing a setting to the redirect URL
- This topic has 6 replies, 2 voices, and was last updated 9 years, 5 months ago by
Ernest Marcinko.
-
AuthorPosts
-
December 8, 2016 at 7:44 pm #11222
MatthewFass
ParticipantHi
I am attempting to follow your instructions here on how to pass additional parameters to the redirect URL: https://wp-dreams.com/knowledge-base/how-to-add-variables-to-the-redirect-to-url-or-the-show-more-url/
[php]// Use this to change the "redirect to url" parameter
add_filter( ‘asp_redirect_url’, ‘asp_add_params_to_url’, 1, 10 );
// Use this to change the "show more results url" parameter
add_filter( ‘asp_show_more_url’, ‘asp_add_params_to_url’, 1, 10 );
function asp_add_params_to_url( $url ) {
// Array of param names and values
$values = array(
"fwp_itemtype" => "MYSETTINGHERE"
);
// Merge them together
foreach ( $values as $k => $v )
$url .= "&".$k."=".$v;return $url;
}[/php]My confusion is how to pass the item_type I have selected in the settings (for example, “event”) to MYSETTINGHERE. Can you clarify.
Many thanks.
-Matthew
Thinking Partners
Red Hook, NYDecember 8, 2016 at 7:48 pm #11223MatthewFass
ParticipantHere’s a screenshot, for clarity sake
December 9, 2016 at 10:51 am #11225Ernest Marcinko
KeymasterHi,
The field values for checkboxes are passed along in the $_POST request variable. Each fieldset group has a unique name to prevent conflicts. The best was to find the name is by simply using the developer tools, in your case: https://i.imgur.com/esNra6o.png
So the selected items will be in the:
[code]$_POST[‘aspf1_11’][‘wpcf-item_type_1’][/code]
array.
But the problem is that you won’t be able to add that there, as this is set only after the search is already printed on the page. The only solution is to create some kind of javascript code to change the redirect url on the FORM element.
-
This reply was modified 9 years, 5 months ago by
Ernest Marcinko.
December 12, 2016 at 11:59 pm #11247MatthewFass
ParticipantOkay, thanks for your reply! I will use JavaScript. But in the meantime, WHAT exactly are these instructions for?
Wouldn’t you want parameters appended to the URLs to be dynamic depending upon what the user has selected?
December 13, 2016 at 12:31 pm #11255Ernest Marcinko
KeymasterHi,
It’s for cases when you want to add static variables based on certian conditions (like current post ID, custom field values, etc..). This is however executed right before the plugin is printed. Dynamically changing the redirection requires javascript, as it’s triggered from the client side (browser), however PHP runs on the server side.
December 13, 2016 at 11:21 pm #11270MatthewFass
ParticipantMany thanks for clearing that up and keep up the great work.
December 14, 2016 at 3:30 pm #11272Ernest Marcinko
KeymasterYou cannot access this content.
-
This reply was modified 9 years, 5 months ago by
-
AuthorPosts
- You must be logged in to reply to this topic.