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

How to get an array of years from all of the search results, and use it to filter by year the paginated loop?

This is really interesting one! I’ve tried to solve this, and here is what I ended up with. With a pure SQL, we have an ability to get all distinct years of all our posts with the following SQL request (recipe founded here): SELECT DISTINCT YEAR(wp_posts.post_date) FROM wp_posts getting something like this: mysql> SELECT DISTINCT … Read more

Search functionality – include date, category and author search

By default, the WordPress search gives an omni-like search facility to WP Posts and Pages that should search any built-in WP content. This can be further extended through a plugin such as Relevanssi. You can though, if I’m understanding you correctly, create a custom search form where you can dictate the fields available to search … Read more

Change default search URL slug in wordpress with Custop Post Type as Search target

Hi Vijay you can try to add post_type as query perameter in you redirect url check following changes in your code. function wp_change_search_url() { if ( is_search() && ! empty( $_GET[‘s’] ) ) { get_query_var( ‘post_type’ ); wp_redirect( home_url( “/search/” ) . urlencode( get_query_var( ‘s’ ) ) . ‘?post_type=” . get_query_var( “post_type’ ) ); exit(); … Read more

How to do multiple searches (with logical OR) in WP_Query in hook pre_get_posts?

You could do something like this add_action(‘pre_get_posts’, ‘bt_search_posts’); function bt_search_posts ($query) { // the posts ids that contain foo bar OR lorem ipsum dolor OR ping pong $posts_ids = []; // get the current query vars $query_vars = $query->query_vars; // loop each term we want to search and if found, add the post id into … Read more

Tags to Post-ID mysql query. Tag Search

These are normal IN mechanics – it matches anything in set, not all of set combined. Type of match you want is called tag_slug__and in WP query arguments. You can see code that generates SQL for it in source of WP_Query->&get_posts() method. Resulting SQL is like this: SELECT p.ID FROM wp_posts p INNER JOIN wp_term_relationships … Read more