Simple Search Form for WordPress
Oct 21, 2020 | PHP, WordPress
<form class="search-xxx" role="search" action="<?php echo site_url('/xxx-url/'); ?>" method="get" id="searchform">
<label>Search</label>
<input name="xxx-value" type="text" required />
<input class="button" type="submit" value="Search" />
</form>
<?php
$search = $_GET['xxx-value'];
$args = array (
'post_type' => 'xxx',
'tag' => $search,
);
$query = new WP_Query( $args );
if ( $query->have_posts() ) {
while ( $query->have_posts() ) { $query->the_post();
$post_id = $query->ID;
}
}
This is a simple search form to use in WordPress