Display post matching the exact search term

Here’s a solution that I came up with that uses a hidden field on the search form which we will later check in our filters to modify WP’s default search/redirect behavior. This is the search form I used. Note the addition of the hidden field barcode-reader with a value of 1. I added the search … Read more

Date_query problems

Since your code returns the posts belonging to 5 years ago, then I assume your problem is in the conditionals, since none of them are run. The form elements must have a name if you want to get their values in the back-end. Your select lacks a name, and you are trying to get its … Read more

WordPress Search matching hyphenated words

It is possible to filter search terms before they are submitted to the actual query using the query_vars hook. So in your case you would do something like this: add_filter (‘query_vars’, ‘wpse307005_filter_search’, 10, 1); function wpse307005_filter_search ($args) { preg_replace (‘Spiderman’,’Spider-Man’,$args[s]); preg_replace (‘Spider man’,’Spider-Man’,$args[s]); return $args; } Where $args[s] holds the search string.

Keep query string in url after executing a serch

It’s hard to say how to do it exactly in your case, because we don’t know how your form is generated… But in general you have to add a hidden input to that form. So if you use searchform.php in your theme, then add something like this to it: <input type=”hidden” name=”name” value=”<?php echo esc_attr( … Read more

Redirect All Search Links Containing – to + on WordPress

You can do something like the following at the top of your .htaccess file to replace all – with + that occur after the /search/ path segment in the requested URL: RewriteRule ^(search/[^-]*)-([^-]*-.*) /$1+$2 [N] RewriteRule ^(search/[^-]*)-([^-]*)$ /$1+$2 [R=302,L] The first RewriteRule loops (internally) until all except 1 hyphen has been replaced with +. The … Read more

WordPress does not find author pages in search

I used this extra query in search.php: $search_string = esc_attr( trim( get_query_var(‘s’) ) ); $wp_user_query = new WP_User_Query( array( ‘meta_query’ => array( ‘relation’ => ‘OR’, array( ‘key’ => ‘first_name’, ‘value’ => $search_string, ‘compare’ => ‘LIKE’ ), array( ‘key’ => ‘last_name’, ‘value’ => $search_string, ‘compare’ => ‘LIKE’ ) ) ) ); With a custom loop: <?php … Read more

Transliterating search term in another language

If you have PHP’s Intl extension installed, you can use the wonderful Transliterator class. I get some pretty good results, like this: $t = Transliterator::create(‘Latin-Greek’, Transliterator::FORWARD ); var_dump( [ ‘alfa’ => $t->transliterate(‘alfa’), ‘alpha’ => $t->transliterate(‘alpha’), ] ); Both these greeklish forms give me “άλφα”. I don’t know how it knows where to put the accent, … Read more

Get PDF in media by ID

Don’t know why, but doing this worked… In my search.php, no problem. In content-search.php, no result. while (have_posts()) : the_post(); $attachment = wp_get_attachment_url(get_the_ID()); set_query_var(‘document’, $attachment); get_template_part(‘template-parts/content’, ‘search’); endwhile; EDIT As mention @Dave Romsey, do add_action( ‘pre_get_posts’, ‘attachment_search’ ); instead of add_filter( ‘pre_get_posts’, ‘attachment_search’ );

Using ElasticSearch on WordPress

So here’s how I recently applied it and what my observations were: An FAQ page was loading at anywhere between 0.6s to 0.9s. It’s a page intended to display all FAQs but broken up into their FAQ categories. (It’s an entirely custom post_type and custom taxonomy.) My team are still adding FAQs from the clients … Read more

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