WordPress Advanced Search query custom fields

WordPress Advanced Search query custom fields

In this Post We Will Explain About is WordPress Advanced Search query custom fields With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to How to Create Advanced Search Form in WordPress for Custom Post TypesExample

In this post we will show you Best way to implement advanced search forms for WordPress-powered sites, hear for Creating a search form for custom fields – WordPresswith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Step 1 : query_search.php

First of all we need to do is open simple your query_search.php file or wherever your search here form is stored. and Then add the simple following fields here inside the form source code:

<!-- Advanced Search For articles -->
<input type="hidden" name="post_type[]" value="articles" />
<!-- Advanced Search For post -->
<input type="hidden" name="post_type[]" value="post" />
<!-- Advanced Search For videos -->
<input type="hidden" name="post_type[]" value="videos" /> 
<!-- Advanced Search For books -->
<input type="hidden" name="post_type[]" value="books" />  

Step 2 : search.php

Next open your simple search.php file and and here paste the following simple codes above your for or any loop content, therefore your list of users can see the all options at the top menu bar.

<form role="search" method="get" id="query_search" action="<?php echo home_url( '/' ); ?>">
<input type="text" name="s" id="s" <?php if(is_search()) { ?>value="<?php the_search_query(); ?>" <?php } else { ?>value="Enter keywords …" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;"<?php } ?> /><br />
	
<?php $query_types = get_query_var('post_type'); ?>

<!-- Advanced Search For books -->
<input type="checkbox" name="post_type[]" value="books" <?php if (in_array('books', $query_types)) { echo 'checked="checked"'; } ?> /><label>Search Books</label>

<!-- Advanced Search For videos -->
<input type="checkbox" name="post_type[]" value="videos" <?php if (in_array('videos', $query_types)) { echo 'checked="checked"'; } ?> /><label>Search Videos</label>

<!-- Advanced Search For articles -->    
<input type="checkbox" name="post_type[]" value="articles" <?php if (in_array('articles', $query_types)) { echo 'checked="checked"'; } ?> /><label>Search Articles</label>

<!-- Advanced Search For post -->
<input type="checkbox" name="post_type[]" value="post" <?php if (in_array('post', $query_types)) { echo 'checked="checked"'; } ?> /><label>Search Blog</label>

<!-- Simple Submit Button-->   
<input type="submit" id="searchsubmit" value="Advanced Search" />
</form>

Example

I hope you have Got What is Creating a search form for custom fields – WordPress And how it works.I would Like to have FeadBack From My Blog(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.


Related FAQ

Here are some more FAQ related to this Article:

  1.   How to print last query in laravel?
  2.   Laravel MySQL Get Last Inserted ID
  3.   Laravel 6 Multiple Where Eloquent Query
  4.   Laravel 5.4 Paypal integration - Paypal Payment Gateway
  5.   Upload Multiple Images With Image Preview Using jQuery,Ajax And PHP
  6.   cURL Requests with Laravel 6 using ixudra/curl
  7.   Laravel Remove Public From URL Steps
  8.   $interval Service using Angular Example
  9.   Laravel Insert Update Delete in Eloquent ORM laravel
  10.   Laravel force https with url helper