First question and first commercial plugin. Woohoo!

I'm trying to create a dashboard widget that leverages user input and a predefined URL structure to create an outbound link that sends the user to his/her desired destination. This is basically a hack created so that users on a blogging network can query another Wordpress site that holds all the content from the bloggers in that network. So if the user enters "pretty cats" and click on the search button, a link appears taking the user to the search page for the aggregating website i.e. http://wordpressag.com/?s=pretty+cats

So far I have the dashboard widget being created and displaying a text field and "search" button, but I'm stumped on the other functions I need to create a link based on the user input. The variable for the user input is $wpag_search, so the desired URL structure would be something akin to http://wordpressag.com?s=($wpag_search) , only with the user input instead of the variable.

Here's what I have, any suggestions?

// Function for displaying text input fields and search button 

function wpag_search_forms() {
    <input id="search_terms" type="text" size="50" name="wpag_search" value="<?php echo esc_attr($wpag_search);?>" />
    <input id="search_button" type="button" value="Search WPAG" class="button-secondary"/>

//Other function for utilizing user input
//Has to follow http://wordpressag.com/?s=(user input) structure

// Create the function use in the action hook

function wpag_plugin_init () {
    wp_add_dashboard_widget('example_dashboard_widget', 'Search The WP Ag Network', 'wpag_search_forms');   

// Hook into the 'wp_dashboard_setup' action to register our other functions

add_action('wp_dashboard_setup', 'wpag_plugin_init' );

  • Have you tried setting the action of the form to the site you want the form to be processed by?
    – mor7ifer
    Feb 20, 2012 at 16:20
  • I hadn't, but by golly, that worked! And with only a few modifications to the original code. Thanks @m0r7if3r! Feb 20, 2012 at 23:11

2 Answers 2


If you set the action of the form to the page which you want to do the processing, it will redirect to that page as well as setting all the $_GET and $_POST variables up for easy access.

  • Demoed the code yesterday to my clients. Success! Feb 24, 2012 at 14:45

You want add_query_arg.

For example,

$url = "http://wordpressag.com"; //base url
$wpag_search = urlencode('myinput'); //replace 'myinput' with user input.
$url = add_query_arg('s',$wpag_search,$url);
//$url is now http://wordpressag.com?s=myinput

Note: add_query_arg expects the input values to be encoded, see urlencode

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.