Search Custom Post Type Custom Fields
Have you tried adding this hidden field to the search form? <input type=”hidden” name=”post_type” value=”news” /> For value=””, you should include the name of your custom post type, of course.
Have you tried adding this hidden field to the search form? <input type=”hidden” name=”post_type” value=”news” /> For value=””, you should include the name of your custom post type, of course.
By default WordPress cannot search in template content. You should import your content into the data base. The plugin HTML Import 2 will help here. Another option is a separate search engine with a parser that can read the complete HTML output. The plugin Search Unleashed for example supports Apache Lucene. That’s probably too much … Read more
You can use Relevanssi – Uncheck all boxes except for “Index and search your Authors” – see screenshot below.
There has been a number of questions and answers on this site regarding returning results based on Geo Location. Please take a look at the following posts: Is it possible to wrap Geo Location search around WP_Query? Optimizing a Proximity-based Store Location Search on a Shared Web Host? How can I implement a location based … Read more
Check if searchform is included? The get_search_form() function (that should be used) uses locate_template(‘searchform.php’); to display the search form. The later returns (as you can see from its source) the template filename if one is located So if you’re just wanting to catch the default way, then you should simply test ‘searchform.php’ === locate_template( ‘searchform.php’ … Read more
You can use filter posts_clauses For example: add_filter( ‘posts_clauses’, ‘post_query_order’, 20, 1 ); function post_query_order( $pieces ) { global $wpdb; $pieces[‘orderby’] = $wpdb->prefix.’posts.post_type ASC’; return $pieces; }
It’s easy to implement. All you need is your own hook for get_terms_args filter: add_filter( ‘get_terms_args’, ‘wpse8170_get_terms_args’, 10, 2 ); function wpse8170_get_terms_args( $args, $taxonomies ) { if ( !in_array( ‘post_tag’, $taxonomies ) ) { return $args; } $matches = array(); if ( empty( $args[‘search’] ) || !preg_match( ‘/^\#(.*)$/’, $args[‘search’], $matches ) ) { return $args; … Read more
This is easy to do using the pre_get_posts action hook to set the orderby to rand in the query, something like this: function random_search_result( $q ) { if ( is_search() && is_main_query() ) $q->set( ‘orderby’, ‘rand’); } add_action( ‘pre_get_posts’, ‘random_search_result’ );
Ok i see my WHERE mistake I made this working solution doesn’t look pretty $i =0; foreach( $searchcol as $col) { if($i==0) { $sqlterm = ‘WHERE’; } else { $sqlterm = ‘OR’; } if(!empty($_REQUEST[“s”])) {$query .= ‘ ‘.$sqlterm.’ ‘.$col.’ LIKE “%’.$search.’%”‘;} $i++; }
With WordPress 4.2.2 I’m using the following (admittedly fragile) method to search excerpts as well as the content and title without a plugin. This is the relevant snippet from functions.php. add_filter(‘posts_where’, ‘custom_posts_where’); function custom_posts_where($where) { if (is_search()) { $where = preg_replace( “/(\w+).post_title LIKE (‘%.*?%’)/”, “$1.post_title LIKE $2) OR ($1.post_excerpt LIKE $2”, $where); } return $where; … Read more