php - Print Form Data Into Array As 'value" -
learning first php search form, gentle!
i'm looking fill 'value' number input on search form. have tried either breaks page or has no effect.
i'm trying input $input_price value part of argument.
here search form
<form method="post" action="http://mysite/searchresults"> <fieldset> <!-- text input selection --> <input type="text" value="<?php the_search_query(); ?>" name="s" id="s" /> <!-- end text input selection --> <input type="text" name="input_price"/> <input type="submit" id="searchsubmit" value="search" /> </fieldset> </form>
and here receiving page
<?php $args['meta_query'][] = array( 'key' => 'price', 'value' => '($input_price)', 'type' => 'numeric', 'compare' => '<=', 'order' => 'dsc' ); $the_query = new wp_query( $args ); ?> <?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?> <h1><?php the_title() ;?></h1> <?php the_excerpt(); ?> <?php endwhile; else: ?> <p>sorry, there no posts display</p> <?php endif; ?>
thanks!
firstly, data being sent receiving script via post http method, can access variables php's $_post
superglobal using element's name
attribute key:
$input_price = $_post['input_price'];
next, brackets around $input_price
should not used here. finally, single quotes not parse variables inside them, in example:
'value' => '($input_price)',
but double quotes will, or not using quotes @ all:
'value' => "$input_price", 'value' => $input_price,
Comments
Post a Comment