Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Multiple questions ( CPT , size title ; stats )
This topic contains 9 replies, has 2 voices, and was last updated by Ernest Marcinko 1 year ago.
- AuthorPosts
- March 18, 2022 at 1:05 pm #37210
Hello,
We have just received the plugin and we have 3 problems or needs:
– Why with the CPT ( add via ( advanced description field )) we don’t have the “Display the description context” functionality working, all the text is displayed in the result
– We want possibility to have in result search a different Font size between title and content ( for up size title )
– Statistics: We would like to know which searches did not return results in dashboard
See attachement for details
Thanks you in advance
William
Attachments:
You must be logged in to view attached files.March 18, 2022 at 2:30 pm #37212Hi,
1. Because that applies only to the contents {descriptionfield} main pseudo variable. The advanced description field is kept as-is, because it may contain HTML and other tags, which should not be tempered with.
2. Sure, you can change that here: https://i.imgur.com/yptTMw7.png
3. That is not stored unfortunately in the local statistics. You can use the google analytics events integration, that can send the number of results.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
March 18, 2022 at 2:48 pm #37214Thank you for your reply
1. is it possible that I can create a hook to apply the same filter? My custom field is equivalent to content of a post
2. sorry i didn’t find it thank you
3. it’s impossible, its a private intranet and google analytics does not comply with our GDPR rules. Can’t you integrate this solution natively? I don’t want to modify your plugin and maintain updates manualy. We mainly bought this plugin for this function, because we had read that it offered analytics and thought that was what it was for. :/
4. There is another request: We use kadence block to create tabs (but it’s the same principle for all tab blocks). When the search result is in a secondary tab, well it would be interesting to have the ID of the div in the URL so that it opens directly.thank you in advance
March 18, 2022 at 3:43 pm #37217Hi,
1. I’m afraid no – that feature is fully hard coded, it can’t be invoked via a hook. How does the advanced content field look like? Can you please copy/paste it here?
3. Only by completely reworking the statistics dashboard. We have that planned, so it will be available in one of the future releases.
4. You can try to custom code that via the asp_results hook – however I don’t know if I recommend that. Requesting the fully filtered post contents each time, then possibly doing DOM manipulations via PHP to detect where the text is – that may cause a lot of server overload and decrease the search performance. There is no generic solution for this I can suggest, it has to be custom coded for the exact page output.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
March 18, 2022 at 3:57 pm #37218Hi,
1.
Post-type :wp --allow-root post-type get fiche +-----------------+---------------------------------------------------------------------------------------------+ | Field | Value | +-----------------+---------------------------------------------------------------------------------------------+ | name | fiche | | label | Fiches de service | | description | | | hierarchical | true | | public | true | | capability_type | post | | labels | {"name":"Fiches de service","singular_name":"Fiche de service","add_new":"Ajouter","add_new | | | _item":"Ajouter un nouveau Fiche de service","edit_item":"Modifier Fiche de service","new_i | | | tem":"Nouveau Fiche de service","view_item":"Voir Fiche de service","view_items":"Voir Fich | | | es de service","search_items":"Recherche de Fiches de service","not_found":"Aucun Fiches de | | | service trouv\u00e9.","not_found_in_trash":"Aucun Fiches de service trouv\u00e9 dans la co | | | rbeille.","parent_item_colon":"Page parente\u00a0:","all_items":"Tous les Fiches de service | | | ","archives":"Tous les Fiches de service","attributes":"Attributs de page","insert_into_ite | | | m":"Ins\u00e9rer dans la page","uploaded_to_this_item":"T\u00e9l\u00e9vers\u00e9s sur cette | | | page","featured_image":"Image mise en avant","set_featured_image":"D\u00e9finir l\u2019ima | | | ge mise en avant","remove_featured_image":"Supprimer l\u2019image mise en avant","use_featu | | | red_image":"Utiliser comme image mise en avant","filter_items_list":"Filtrer la liste des p | | | ages","filter_by_date":"Filtrer par date","items_list_navigation":"Navigation de la liste d | | | es pages","items_list":"Liste des pages","item_published":"Page mise en ligne.","item_publi | | | shed_privately":"Page mise en ligne en priv\u00e9.","item_reverted_to_draft":"Page reconver | | | tie en brouillon.","item_scheduled":"Page planifi\u00e9e.","item_updated":"Page mise \u00e0 | | | jour.","item_link":"Lien de page","item_link_description":"Un lien vers une page.","menu_n | | | ame":"Fiches de service","name_admin_bar":"Fiche de service"} | | cap | {"edit_post":"edit_post","read_post":"read_post","delete_post":"delete_post","edit_posts":" | | | edit_posts","edit_others_posts":"edit_others_posts","delete_posts":"delete_posts","publish_ | | | posts":"publish_posts","read_private_posts":"read_private_posts","read":"read","delete_priv | | | ate_posts":"delete_private_posts","delete_published_posts":"delete_published_posts","delete | | | _others_posts":"delete_others_posts","edit_private_posts":"edit_private_posts","edit_publis | | | hed_posts":"edit_published_posts","create_posts":"edit_posts"} | | supports | {"title":true,"editor":true,"thumbnail":true,"excerpt":true,"revisions":true,"author":true, | | | "page-attributes":true,"post-formats":true} | +-----------------+---------------------------------------------------------------------------------------------+
– Advanced Custom Field :
"fields": [ { "key": "field_58b971c1ab7ef", "label": "Description", "name": "description_fr", "type": "wysiwyg", "instructions": "", "required": 1, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "default_value": "", "tabs": "all", "toolbar": "full", "media_upload": 1, "delay": 0 }, { "key": "field_58b871c1ab7ef", "label": "Description", "name": "description_en", "type": "wysiwyg", "instructions": "", "required": 1, "conditional_logic": 0, "wrapper": { "width": "", "class": "", "id": "" }, "default_value": "", "toolbar": "full", "media_upload": 1, "tabs": "all", "delay": 0 },
In your plugin setting i set “{descriptionfield}{description_fr}{description_en} ”
3. Ok thanks we wait
4. Ok I want try to dev this with jquery after loading page with _POST var
Thanks
WilliamMarch 21, 2022 at 2:54 pm #37231Thanks.
Okay, the context feature should execute on the
{descriptionfield}
section, but no on{description_fr}{description_en}
section. I’m afraid there is no easy way of forcing that behaviour.You can try a custom code, but that will be much less efficient, and may not work in all cases.
Try adding this code to the functions.php file in your theme/child theme directory – make sure to have a full server back-up first for safety. For more details you can check the safe coding guidelines.
Best,function text_context_find($s, $content) { if ( $s !== '' ) { $regex = '/([A-Za-z0-9.,-]+\s*){0,5}\s'.$s.'(\s|[,.!?])(\s*[A-Za-z0-9.,-]+){0,40}/'; preg_match($regex, $content, $matches); if ( $matches[0] !== '' ) { if ( str_starts_with($content, $matches[0]) ) { if ( $matches[0] != $content ) { return $matches[0] . '...'; } else { return $matches[0]; } } else { return '...' . $matches[0] . '...'; } } } return $content; } function asp_context_find( $results, $search_id, $is_ajax, $args ) { foreach ($results as $k=>&$r) { $r->content = text_context_find($args['s'], $r->content); } return $results; } add_filter( 'asp_results', 'asp_context_find', 10, 4 );
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
March 23, 2022 at 4:08 pm #37285Hello
Indeed this code does not work correctly and I can’t edit to that it is functional.
If the text of the CPT contains in the middle the word it’s ok
For all other cases (even non-CPT) there is only “……” so match[0] is always empty
I think it comes from the regex but I can’t find what you are using
ThanksMarch 24, 2022 at 2:38 pm #37303Well, context word finding is a bit more complicated than this, I can try to copy paste the same function we use in the core, but this may not work at all:
Best,function x_context_find($str, $needle, $context, $maxlength, $str_length_limit = 10000, $false_on_no_match = false) { $haystack = remove_accents(' '.trim($str).' '); $haystack = wd_substr_at_word(ASP_mb::strtolower($haystack), $str_length_limit, ''); $needle = remove_accents(ASP_mb::strtolower($needle)); if ( $needle == "" ) { if ( ASP_mb::strlen($str) > $maxlength) { return wd_substr_at_word($str, $maxlength); } else { return $str; } } $chrArray = preg_split('//u', $haystack, -1, PREG_SPLIT_NO_EMPTY); $hay_length = count($chrArray) - 1; if ( $i = ASP_mb::strpos($haystack, $needle) ) { $start=$i; $end=$i; $spaces=0; while ($spaces < ((int) $context/2) && $start > 0) { $start--; if ($chrArray[$start] == ' ') { $spaces++; } } while ($spaces < ($context +1) && $end < $hay_length) { $end++; if ($chrArray[$end] == ' ') { $spaces++; } } while ($spaces < ($context +1) && $start > 0) { $start--; if ($chrArray[$start] == ' ') { $spaces++; } } $str_start = ($start - 1) < 0 ? 0 : ($start -1); $str_end = ($end - 1) < 0 ? 0 : ($end -1); $result = trim( ASP_mb::substr($str, $str_start, ($str_end - $str_start)) ); // Somewhere inbetween.. if ( $start != 0 && $end < $hay_length ) return "... " . $result . " ..."; // Beginning if ( $start == 0 && $end < $hay_length ) return $result . " ..."; // End if ( $start != 0 && $end == $hay_length ) return "... " . $result; // If it is too long, strip it if ( ASP_mb::strlen($result) > $maxlength) return wd_substr_at_word( $result, $maxlength ); // Else, it is the whole return $result; } else { if ( $false_on_no_match ) return false; // If it is too long, strip it if ( ASP_mb::strlen($str) > $maxlength) return wd_substr_at_word( $str, $maxlength ); return $str; } } function asp_context_find( $results, $search_id, $is_ajax, $args ) { foreach ($results as $k=>&$r) { $r->content = x_context_find($r->content, $args['s'], floor(ASP_mb::strlen($r->content) / 6), 130); } return $results; } add_filter( 'asp_results', 'asp_context_find', 10, 4 );
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
March 25, 2022 at 10:31 am #37306Hello Ernest,
I work with this on PJ
( i cant set here because your ticket software block my response )Does this seem coherent to you?
Attachments:
You must be logged in to view attached files.March 25, 2022 at 1:27 pm #37308Hi,
Yes, that looks okay to me.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
- AuthorPosts
You must be logged in to reply to this topic.