Customization to index files from wp downloads manager to Elasticsearch
- supportParticipant4 years, 7 months ago #21376
Dear WPSolr team,
I would like to make use of your plugin in order to index documents and pdf files to Elasticsearch and enable a full text search feature on my website.
Actually, the website uses WP Download Manager (https://www.wpdownloadmanager.com/) in order to organise their files. So those are custom post types that save the file
May you send a quotation for this kind of customization?
Thank you.
Best regards,
Hendrik
supportParticipant4 years, 7 months ago #21379Hi there,
I gave it a try because the “Download” post type is recognized.
If I search for a word that is included in the “Download” post name, WPSolr find it, unfortunately I can’t search text inside any pdf file linked to this post type.Even by checking all fields and taxonomies, when I export my data to Elasticsearch, I don’t see a big difference in index size compared to the difference when I ingest other media files.
There should be 140 pdf files ingested into the index.For information, those files aren’t inside the post description, but uploaded in a dedicated WP download manager field on the post itself. Those files also aren’t displayed through the WordPress media file system.
If you have any knowledge with this kind of behavior, do you have any hypothesis to resolve this?
Thank you.
Best regards,
Hendrik
supportParticipant4 years, 6 months ago #22083Hi there,
Apparently my answer didn’t go through.
I’ve tried to manually and a direct link to the pdf in the post meta fields, but those files aren’t taken into Elasticsearch.
The wpdownloads attachement field isn’t a standard file type as the files aren’t managed through the WordPress medias.How may I achieve this then ?
Thank you.
Best regards,
Hendrik
supportParticipant4 years, 6 months ago #22091Hi there,
As explained WP download manager has no relation to ACF file field.Best File / Document Management & Digital eCommerce Plugin for WordPress
The plugin has a file field like here:
__wpdm_files : a:1:{i:0;s:46:”5e312bd311838c_filename.pdf”;}
I can programmatically add a URL to the pdf file, but not a File type field as ACF makes use of.
Please, may it be possible to estimate how WPSOLR might include WP download manager files?Thank you.
Best regards,
Hendrik
supportParticipant4 years, 5 months ago #22175Hi there,
I found my way by adding a filter in the functions.php file of my theme.
If anyone is looking to index WP Download Manager Pro downloads with WPSolr, here you go/* * Add WP download manager attachements in WPSolr indexer */ use wpsolr\core\classes\WPSOLR_Events; add_filter( WPSOLR_Events::WPSOLR_FILTER_GET_POST_ATTACHMENTS, 'filter_get_wpdm_post_attachments', 10, 2 ); function filter_get_wpdm_post_attachments( $attachments, $post_id ) { if ( get_post_type( $post_id ) != 'wpdmpro' ) { return $attachments; } $wpdm_files = get_post_meta( $post_id, '__wpdm_files', true ); if ( ! empty( $wpdm_files ) ) { foreach ( $wpdm_files as $key => $file_name ) { $download_link = get_permalink( $post_id ).'?wpdmdl='.$post_id."&ind=".$key."&filename=".$file_name; array_push( $attachments, [ 'url' => $download_link ] ); } } return $attachments; }
supportParticipant4 years, 5 months ago #22177I’ve enhanced the function a little bit by disabling locked downloads indexing
/* * Add WP download manager attachements in WPSOLR indexer */ add_filter( WPSOLR_Events::WPSOLR_FILTER_GET_POST_ATTACHMENTS, 'filter_get_wpdm_post_attachments', 10, 2 ); function filter_get_wpdm_post_attachments( $attachments, $post_id ) { if ( 'wpdmpro' != get_post_type( $post_id ) ) { return $attachments; } $wpdm_files = get_post_meta( $post_id, '__wpdm_files', true ); $wpdm_locked = wpdm_is_locked( $post_id ); if ( ! empty( $wpdm_files ) && !$wpdm_locked ) { foreach ( $wpdm_files as $key => $file_name ) { $download_link = get_permalink( $post_id ).'?wpdmdl='.$post_id."&ind=".$key."&filename=".$file_name; array_push( $attachments, [ 'url' => $download_link ] ); } } return $attachments; }
You must be logged in to reply to this topic.