This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: Error 500 with AjaxSearchPro Plugin

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Error 500 with AjaxSearchPro Plugin Reply To: Error 500 with AjaxSearchPro Plugin

#52885
Ernest MarcinkoErnest Marcinko
Keymaster

Thanks!

The issue is caused by the custom code as it uses the “yoast_get_primary_term_id” function, but the Yoast SEO plugin is disabled, so that no longer exists. I made a modification to it to check if the function exists first:

add_filter(
    'asp_results',
    function ( $results, $id, $is_ajax, $args ) {
        foreach ( $results as $r ) {
			if ( function_exists('yoast_get_primary_term_id') ) {
				// Intenta obtenir la categoria principal amb Yoast
				$main_term_id = yoast_get_primary_term_id( 'category', $r->id );
			} else {
				$main_term_id = false;
			}
            
            
            
            // Si no hi ha categoria principal, obtenim la primera categoria disponible
            if ( empty($main_term_id) ) {
                $terms = get_the_terms( $r->id, 'category' );
                if ( !empty($terms) && !is_wp_error($terms) ) {
                    // Prenem la primera categoria disponible
                    $term = reset($terms);
                } else {
                    continue;
                }
            } else {
                // Si hi ha categoria principal, la utilitzem
                $term = get_term( $main_term_id );
                if ( empty($term) ) {
                    continue;
                }
            }

            // Afegeix la categoria als resultats
            $r->content = 
                '<div class="result-cat-container"><span class="result-cat">'.$term->name.'</span></div>' . $r->content;
        }
        return $results;
    },
    10,
    4
);