Search bar for page that searches only particular page IDs

You can try to modify your filter like this function pregetposts_forspecificpage($query){ if(!is_admin() && $query->is_main_query() && is_search()) { $query->set(‘post_type’, ‘page’); $query->set(‘post__in’, array(22103,22121)); } } Edit : added !is_admin() because we only want to alter the query in the front. $query->is_main_query() to be sure that we are altering the main query. Replaced $query->is_search by is_search() Also, you … Read more

Display result of custom form

First, your code attempts to use $_POST[‘nom’] whether the value is set or not. You are generating non-fatal “Undefined index” warning every time that runs. Clean that up and use !empty($_POST[‘nom’]) instead of $_POST[‘nom’]!=NULL. With template_redirect you’d want to redirect to an existing page, something like the following from another answer: function redirect_cat_wpse_207298() { if … Read more

Search pagination link redirecting to a link that doesn’t work with pagination

If your are using a custom template I assume you are using a custom loop so first populate $paged. <?php $max_posts = get_option(‘posts_per_page ‘); ?> <?php global $paged; ?> <?php if ( get_query_var(‘paged’) ) { $paged = get_query_var(‘paged’); } elseif ( get_query_var(‘page’) ) { $paged = get_query_var(‘page’); } else { $paged = 1; } ?> … Read more

WordPress search for specific Post Type

Yes this is possible. There are numerous ways in which you can achieve this, either by creating a custom form and workflow or by overriding the default search template in WordPress and supply a request parameter for which can be used to identify the search request and filter the post types that should be searched. … Read more

How can I prevent the Search Results Page from changing title?

You can replace: <h1 class=”site-title”><?php echo get_the_title($post->ID); ?></h1> With: <h1 class=”site-title”><?php _e( ‘Search results for’, ‘theme-textdomain’ ).’: ‘ . get_search_query(); ?></h1> But obviously only in search pages. I suggest to move the <h1> element to each template you may need instead of include it in the general header.php template. It is up to you but … Read more