Skip Navigation

[Résolu] show relevance of results

This support ticket is created Il y a 4 années et 3 mois. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 15 réponses, has 2 voix.

Last updated by Ido Angel Il y a 4 années et 3 mois.

Assisted by: Waqar.

Auteur
Publications
#1406249
add_shortcode( 'show_results_relevance', 'show_results_relevance_func');
function show_results_relevance_func($atts) {
    // get the searched terms for main ingredients
    $searched_recipe_main_ingredient = do_shortcode('[wpv-search-term param="wpv-main-ingredient"]');
    if(!empty($searched_recipe_main_ingredient))
    {
        $searched_recipe_main_ingredient_arr = explode(", ", $searched_recipe_main_ingredient);
        // count of searched main ingredients
        $searched_recipe_main_ingredient_count = count($searched_recipe_main_ingredient_arr);
 
        // get attached main ingredients for current post
        $attached_main_ingredients = do_shortcode("[wpv-post-taxonomy type='main-ingredient' format='name' separator=', ']");
 
        if(!empty($attached_main_ingredients))
        {   
            $attached_main_ingredients_arr = explode(", ", $attached_main_ingredients);
			
            // count of common ingredients which were searched and are also attached
            $matched_main_ingredients = count(array_intersect($searched_recipe_main_ingredient_arr,$attached_main_ingredients_arr));        
        }
        else
        {
            $matched_main_ingredients = 0;
        }
 
    }
    else
    {
        $searched_recipe_main_ingredient_count = 0;
        $matched_main_ingredients = 0;
    }
 



	return ($matched_main_ingredients/$searched_recipe_main_ingredient_count*100);

}

WINNNN!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.