Limit search to posts and pages

and add this to functions.php if you want to search only in posts and pages. function mk_searchfilter($query) { if ($query->is_search && !is_admin() ) { $query->set(‘post_type’,array(‘post’,’page’)); } return $query; } add_filter(‘pre_get_posts’,’mk_searchfilter’);

How to search for articles containing two words?

Ex. http://www.site.com/?s=as+sa This gives a perfect search result irrespective of the order of words. If you want to add a custom query then you can use following: $query = new WP_Query( ‘s=keyword+keyword2’ ); and iterate through your query result. Try this out.

How do I turn this form into a search form? [closed]

Please try this , <form name=”searchBox” action=”<?php echo get_bloginfo(‘url’); ?>” class=”search-form” method=”get” role=”search” > <input type=”text” name=”s” class=”searchBox” placeholder=”search” value=”<?= $_GET[‘s’] ?>” required /> <button type=”submit” class=”searchBtn” >search</button> </form>

Search and replace titles of posts with specific tags

//Search by tags $query = new WP_Query( ‘tag=old’ ); // Then update post titles if ( $query->have_posts() ) { while ( $query->have_posts() ) { $query->the_post(); //check if title have “a new” if(strpos(get_the_title(),’a new’) !== false) : $post = array( ‘ID’=> get_the_id(), ‘post_title’=> str_replace(‘a new’,’an old’,get_the_title()) ); // Update the post into the database wp_update_post( $post … Read more