How to exclude post body from WP search

To remove elements from being searched, use the post_search filter to amend the SQL query for the search e.g. only pull in the title. function ni_search_by_title_only( $search, &$wp_query ){ global $wpdb; if ( empty( $search ) ) return $search; $q = $wp_query->query_vars; $n = ! empty( $q[‘exact’] ) ? ” : ‘%’; $search = $searchand … Read more

Return all Tags from search results

The global $wp_query object is available before you call have_posts(). All you have to do is running through this object’s posts member with get_the_terms(). Sample function: function get_query_terms( $taxonomy = ‘post_tag’ ) { $list = array (); foreach ( $GLOBALS[‘wp_query’]->posts as $id ) { if ( $terms = get_the_terms( $id, $taxonomy ) ) { foreach … Read more

Backend search; include CPT meta?

Untested, but the following should work: add_action( ‘posts_clauses’, ‘wpse110779_filter_admin_search’, 10, 2 ); function wpse110779_filter_admin_search( $pieces, $query ){ global $wpdb; //Check if this is the main query,and is a search on the admin screen if( $query->is_search() & $query->is_admin() && $query->is_main_query() ){ //Collect post types & search term $post_types = $query->get(‘post_type’); $search = $query->get(‘s’); //Check if query … Read more

How to stop _wpnonce and _wp_http_referer from appearing in URL

This issue arrises because of a couple of problems: 1) WP_List_Table::search_box() inserts the default _wpnonce and _wp_http_referer fields by using wp_nonce_field() without giving you the ability to override and say “I’ve already go a nonce field thanks”. 2) You need to use GET as your method of form submission when subclassing WP_List_Table because WP_List_Table::print_column_headers() only … Read more

Search for tags

Yes its very possible, you just need to create your own search form and processing function form: <form name=”tag-search” method=”POST” action=””> <input type=”text” vlaue=”” name=”tag-q” id=”tag-q”> <input type=”submit” name=”tag-submit” id=”tag-submit” value=”Search Tags”> </form> processing: <?php if (isset($_POST[‘tag-submit’]) && $_POST[‘tag-submit’] == “Search Tags” && isset($_POST[‘tag-q’]) && $_POST[‘tag-q’] != “”){ // @todo Sanity check and cleanup $_POST[‘tag-q’] … Read more