New answers tagged

0

There are many jQuery plugins designed specifically for this functionality. Check these ones out: http://www.jqueryrain.com/demo/jquery-multiselect-plugin/


0

As far as I remember WP core doesn't do this natively, though I think there are/were some considerations about adding select2 for tasks like this. Might be mistaken on this. However there are a lot of frameworks around, which implement additional UI for things like this. It's pretty common feature in them. I tend to use Meta Box, which should be able to do ...


0

Found an answer by myself. Hope it will help others with the same issue. Basically, the search-everything plugin responds to an wp_ajax_{#action} type action. One 'problem' is that it only responds for logged-in users, so we must add a nopriv action to functions.php or the like: add_action('wp_ajax_nopriv_search_everything', 'search_everything_callback'); ...


0

Try this function search_pre_get_posts( $query ) { if ( $query->is_search() && $query->is_main_query() ) { $currentdate = date('Y-m-d'); $enddate = strtotime(date('Y-m-d') . "+7 days"); $enddate = date('Y-m-d',$enddate); $query->set( 'meta_query', ...


0

First, the pre_get_posts hook is an action and not a filter. Then the meta_query parameter should contain the relation only if there is more than one inner meta_query array (codex). Finally you do not need to return the $query argument as it is passed by reference to your callback function. Your code should look like this: function ZoekGeenLegeItems( ...


0

You need to search for more information on AJAX. There are some plugins that may do what you are looking for such as: https://wordpress.org/plugins/ajax-search-lite/ Alternatively, if you want to try and develop the code yourself, have a look at the following: ...


2

Wordpress also provide more filter to can change wp query using filters. What i need logical to use filter to override query below sample of code if this helpful for you. add_filter( 'posts_where', 'posts_where_condition_search' ); $wp_query = new WP_Query( array( 'post_type' => 'press-release', 'posts_per_page' => ...


0

SOLVED! In response to @tomjnowell : Yep! you are right, I'm not giving enough details nor context, sorry. I'm not used to post questions here, nor the english is my mother tongue, as you can see. So thanks to be so patient as to help me. What I wanted What I intended is to make a search by several post meta AND, optionally, ALL the post meta PLUS the ...


0

Create a another filter to remove post title and post content remove search terms try this if this helpful for you add_filter( 'posts_search', 'custom_post_search_author_do', 10, 2 ); function custom_post_search_author_do($search, $query ){ if( ! empty($search) && $query->is_main_query() && !is_admin() ...


0

The parameter for meta query is meta_key, not just key (according to https://codex.wordpress.org/Class_Reference/WP_Query) Try 'meta_key' => 'autor' instead of 'key' => 'autor'


0

If you want to use WordPress you can download a custom post type plugin (such as Custom Post Type UI), create your Book post type; another plugin to generate your form for adding books (Gravity Forms + this looks good, or a similar solution, or create a form by hand). Then tweak the default WordPress search feature to search through Book post type only (you ...


0

Fixed: Search and result the all keys; <?php $the_keys = preg_split('/\s+/', str_replace('-',' ',get_query_var('s')),-1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); $total_keys = count($the_keys); $the_query = new WP_Query(array('post_type'=>'nothing')); if($total_keys>1){ for($i = 0; ...


0

Maybe somebody like me want fuzzy logic results I solved this way: "search.php" <?php $the_keys = preg_split('/\s+/', get_query_var('s'),-1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE); $total_keys = count($the_keys); // Count the search term $the_query = new WP_Query(array('s' => get_query_var('s'))); // IF have ...


0

You are getting into deep water quickly. I would look into SearchWP plugin as they provide LIKE searching and Fuzzy matching. SearchWP


0

add_action('pre_get_posts','search_filter_exc_posts'); function search_filter_exc_posts($query) { // Verify that we are on the search page & this came from the search form if($query->query_vars['s'] != '' && is_search()) { $q_tax_query = $query->query_vars["tax_query"]; // append product categories to current tax ...


1

You may need to include a tax_query for the Woocommerce taxonomy (called 'product_cat'): $tax_query = array( array( 'taxonomy' => 'product_cat' ), ); $query->set( 'tax_query', $tax_query ); } return $query; } However, you'll have to ensure that you can return posts AND pages AND product categories and also ...


0

You can simply put this in your functions.php file. function SearchFilter($query) { if (($query->is_search)&&(!is_admin())) { $query->set('post_type', 'post'); } return $query; } add_filter('pre_get_posts','SearchFilter');


1

The WP_Query class can match IDs as well as search terms. An idea would be to use the pre_get_posts action to detect if the search term is numeric and, if it is, set the query to work with attachments while passing the search as the ID. function wpse223307_allow_search_by_attachment_id( $query ) { //Only alter the query if we are in a search screen,... ...


0

If you want to change the search behavior, then, all you need to do is add your own fields to the form <form role="search" method="get" id="searchform" action="http://www.test.dev/"> <div> <label for="s">Search for:</label> <input type="text" value="" name="s" id="s" /> <input type="hidden" value="1" name="sentence" /> ...


2

That site you linked to is completely wrong. You should never ever use query_posts to run any type of query. Take your time and read the following post on this matter: When should you use WP_Query vs query_posts() vs get_posts()? You also would not want to run any type of custom query in place of the main query, this raises/causes more issues than what ...


0

After Milo's help I found a function where it altered the search query: if( is_search() && empty($_GET['post_type']) && !is_admin() ) { global $wpdb; $query = get_search_query(); $query = $wpdb->esc_like( $query ); $where .= " OR {$wpdb->posts}.ID IN ("; ...



Top 50 recent answers are included