Continue reading Proximity sorting

Proximity sorting

…post. You give the location with the relevanssi_proximity_coordinates filter hook, which filters the coordinates and gets the post ID as the parameter. Often the coordinates are in a custom field. The necessary function will look something like this: add_filter( ‘relevanssi_proximity_coordinates’, function( $coordinates, $post_id ) { return get_post_meta( $post_id, ‘coordinates’, true……on the relevanssi_proximity_comparison filter hook. That function should return the coordinates as a string. If you don’t use the coordinates query variable, you need this snippet to remove a PHP warning: add_action( ‘init’, function() { remove_filter( ‘relevanssi_search_params’, ‘relevanssi_pick_up_coordinates’ ); } ); Then you need to provide the coordinates for each……a fixed spot or something the search user provides. Relevanssi looks for this in the coordinates query variable and it should have the coordinates in the “latitude, longitude” format. If this is not possible or easy, you can also provide the coordinates with a filter function. Add a filter function…

Read more Proximity sorting 0 Comment on Proximity sorting
Continue reading Redirecting email searches to the login page

Redirecting email searches to the login page

A client asked for a solution to redirect all searches for email addresses to the login page – perhaps someone is constantly using the search field when they’re actually looking for the login. This can be achieved with the Redirects tool, as it takes regular expressions. You can also add this to your site: This function…

Read more Redirecting email searches to the login page 0 Comment on Redirecting email searches to the login page
Continue reading MemberPress Downloads add-on

MemberPress Downloads add-on

The Downloads add-on for MemberPress adds downloadable files to MemberPress. These files are stored outside the Media Library, so by default Relevanssi attachment indexing has no access to them. However, Relevanssi offers filter hooks you can use to make Relevanssi index the MemberPress Downloads files. Adjust the query First, we……need to tell Relevanssi to look for mpdl-file posts instead of attachment posts using the relevanssi_get_attachment_posts_query filter hook. By default, Relevanssi looks for posts with the post type attachment, post status inherit and a suitable MIME type. These all need to be changed, because the Downloads posts have the post……to modify the name and path of the file sent to Relevanssi: add_filter( ‘relevanssi_get_attached_file’, ‘rlv_mpdl_file’, 10, 2 ); /** * Filters the name and path of the file. * * Gets the file name from the _mpdl_file_filename custom field of the download file * post and corrects the path, too….

Read more MemberPress Downloads add-on 0 Comment on MemberPress Downloads add-on
Continue reading Download Monitor: Index PDF content for parent page

Download Monitor: Index PDF content for parent page

Relevanssi can handle Download Monitor files without significant problems. If you want to use the “Index PDF contents for the parent page” option, there’s a problem, though. Download Monitor comes in between: the PDF post is attached to the Download Monitor dlm_download post and not the page where the [download]……grab that. $download_id = preg_replace( ‘/[^\d]/’, ”, $meta_field_value ); if ( $download_id ) { // Replace the original post_parent ID with the new one. $query = preg_replace( ‘/post_parent = \d+/’, “post_parent = $download_id”, $query ); } } return $query; } If the [download] shortcode is somewhere in the post content,……string The modified MySQL query. */ function rlv_download_monitor( $query, $post_id ) { $post_object = relevanssi_get_post( $post_id ); $id_matches = preg_match_all( ‘/\[download id=.(\d+).\]/ims’, $post_object->post_content, $matches ); if ( $id_matches ) { $download_id = implode( ‘,’, $matches[1] ); $query = preg_replace( ‘/post_parent = \d+/’, “post_parent IN ($download_id)”, $query ); } return $query;…

Read more Download Monitor: Index PDF content for parent page 3 Comments on Download Monitor: Index PDF content for parent page
Continue reading ThemeCo

ThemeCo

ThemeCo themes use custom codes for dynamic content. Those are not usual shortcodes, and Relevanssi won’t expand them automatically. In order to expand the dynamic content from ThemeCo themes, you need to use these filters: The critical part is running these filters on an early enough priority for relevanssi_post_content: Relevanssi page builder shortcode cleanup runs…

Read more ThemeCo 0 Comment on ThemeCo
Continue reading Premium 2.15.3 / Free 4.13.3

Premium 2.15.3 / Free 4.13.3

These versions collect all the bug fixes and small improvements that I ran into during the summer. Next up is Premium 2.16, which will add bigger new features: at the moment I’m looking at developing proximity sorting (ie. show results that are nearest based on coordinates) and better search tracking….

Read more Premium 2.15.3 / Free 4.13.3 0 Comment on Premium 2.15.3 / Free 4.13.3
Continue reading WPML: Replacing posts with translations

WPML: Replacing posts with translations

…the translated posts. You get a wider range of results, but all in the current language. This solution works best when all your posts appear in all languages. To use this, add this code to your site: remove_filter( ‘relevanssi_hits_filter’, ‘relevanssi_wpml_filter’ ); // Remove the original WPML filter. add_filter( ‘relevanssi_hits_filter’, ‘relevanssi_wpml_filter_show_translation’…$data[1]; } return array( $filtered_hits, $query ); } This is almost the same as the default WPML compatibility in Relevanssi. Relevanssi checks if the post has a translation in the current language. Usually in that case Relevanssi discards the post, because it’s in the wrong language. Here Relevanssi adds the……); // Replace with our new filter. function relevanssi_wpml_filter_show_translation( $data ) { $wpml_post_type_setting = apply_filters( ‘wpml_setting’, false, ‘custom_posts_sync_option’ ); $current_blog_language = get_bloginfo( ‘language’ ); $filtered_hits = array(); foreach ( $data[0] as $hit ) { $original_hit = $hit; $object_array = relevanssi_get_an_object( $hit ); $hit = $object_array[‘object’]; $format = $object_array[‘format’]; if (…

Read more WPML: Replacing posts with translations 0 Comment on WPML: Replacing posts with translations