Search with filters

Here is one to create a search form with tag and category filters. For filtering posts this form uses the default text input way, where user can type some search phrase that is matched against post titles and content. 1) Added to theme’s functions.php function get_tag_ids_and_names() { $out = array(); $arga = array( // check … Read more

Limiting WordPress Search function : Custom build

This code will only search form woocommerce products. If you want to show any other search result from another post type you can do by simply change post type slug ‘product’ with you own post type slug add_action( ‘pre_get_posts’, ‘wpse223576_search_woocommerce_only’ ); function wpse223576_search_woocommerce_only( $query ) { if( ! is_admin() && is_search() && $query->is_main_query() ) { … Read more

Replacing word in wordpress Search not working Properly

Your code says, “If the search term isn’t empty, and that exact search term is in my search replacements array, then replace the term.” So, instead of this: !empty($search_replacements[$request_vars[‘s’]] (which means, if this exact search term [$request_vars[‘s’] is in my $search_replacements array) you’ll need to instead loop through your search replacements array every time someone … Read more

Woocommerce: Search by custom attribute

First verify your product attribute (meta_key) by running this query Note: Change table prefix according to your wordpress database mine is default wp_ SELECT * FROM wp_postmeta WHERE meta_key LIKE ‘%code%’; /* get attribute name example (_sku, _stock, _stock_status, height, width )*/ Now add this to your functions.php file function Add_custom_search( $query ) { if( … Read more

Including taxonomy in searches

First you want to make the query keys available so you can check them later: add_action( ‘init’, ‘custom_add_query_vars’ ); function custom_add_query_vars() { add_query_var( ‘location’ ); add_query_var( ‘tag’ ); } Then you want to set a tax_query by filtering the WP Query: add_filter( ‘pre_get_posts’, ‘custom_search_tax_query’ ); function custom_search_tax_query() { // check this is a search query … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)