Search outside of the “loop”
You can use get_posts() with a search parameter: $results = get_posts( array( ‘s’ => ‘search term’ ) );
You can use get_posts() with a search parameter: $results = get_posts( array( ‘s’ => ‘search term’ ) );
The built in WordPress search doesn’t index PDF file contents, however Google does, there’s a good tutorial on DevPress on replacing WordPress search with Google Custom Search.
Well, the s is not just a name/ID, it’s a query var, as the form’s fields are injected by means of GET or POST to the URL which is then checked for the s query var. If the s query var is defined, the search.php (if present in your theme) will then be called automatically. … Read more
ElasticPress Indexing multiple sites
In line 51: query_posts(“s=”$s”&cat=177”); change to this: $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; query_posts(“s=”$s”&cat=177&paged=$paged”);
Alright, I’ve solved the problem. Turns out that you should never use action=”” for searchform.php. It will work perfectly fine in terms of search results, but it will break the pagination, when using 3.1. Instead, you should use for the form action.
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
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
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
you can change your search filter to this: function SearchFilter($query) { $post_type = $_GET[‘post_type’]; if (!$post_type) { $post_type=”any”; } if ($query->is_search) { $query->set(‘post_type’, $post_type); }; return $query; } add_filter(‘pre_get_posts’,’SearchFilter’); then on your news search form add : <input type=”hidden” name=”post_type” value=”post” /> on your custom post type listing search form add <input type=”hidden” name=”post_type” value=”customtypename” … Read more