Show only “Pages” – not posts – on search page

Setting the post type at pre_get_posts can solve this. You can set it like below- function the_dramatist_search_only_page($query) { if ($query->is_search && !is_admin() ) { $query->set(‘post_type’,array(‘page’)); } return $query; } add_filter(‘pre_get_posts’,’the_dramatist_search_only_page’); Hope it helps.

Input type search in Menu

This is fine, but you if you want things to look “cleaner” and be easier to modify you could instead create a new file menu-search.php and add your HTML there then tweak your function a bit (don’t forget to prefix your functions) function myprefix_add_search_box_to_menu($items, $args) { if ( $args->theme_location == ‘menu-1’ ) { ob_start(); get_template_part( … Read more

I need to create a search form that will display search results from specific category

You can use WP_query() to narrow down the results of your search: <?php $args = array( ‘s’ => $_GET[‘s’], ‘post_type’ => array( ‘post’, ‘page’ ), ‘post_status’ => ‘publish’, ‘category_name’ => ‘music’, ‘posts_per_page’ => -1 ); $custom_search = new WP_Query( $args ); if ( $custom_search->have_posts() ) { while ( $custom_search->have_posts() ) : $custom_search->the_post(); ?> <div class=”entry-content”> … Read more

How to make wordpress Dynamic Search-Bar from Predesigned Static Html Search-Bar?

Yes, it’s pretty easy to make our static HTML Search-Bar dynamic. First, wrap up our <input />tag with <form> </form> tag mentioning action=”” and mehotd=”” Second, identify the default key of wordpress and assign it in name=”” attribute of input tag. To be specific, the code would be like this: <form method=”GET” action=”<?php bloginfo(‘home’); ?>”> … Read more

Display post matching the exact search term

Here’s a solution that I came up with that uses a hidden field on the search form which we will later check in our filters to modify WP’s default search/redirect behavior. This is the search form I used. Note the addition of the hidden field barcode-reader with a value of 1. I added the search … Read more

Date_query problems

Since your code returns the posts belonging to 5 years ago, then I assume your problem is in the conditionals, since none of them are run. The form elements must have a name if you want to get their values in the back-end. Your select lacks a name, and you are trying to get its … Read more