FacetWP Proximity from customfield

Save coordinates as customfield “coordinaten” with format [latitude],[longitude]. These terms wil be split so facetwp can pass the location to Google.

add_filter('facetwp_index_row', function ($params, $class) {
    if ('proximity' == $params['facet_name']) {
        if (!empty($params['facet_value'])) {
            $related_post_id = $params['term_id'];
            $coordinaten = get_term_meta($related_post_id, 'coordinaten', true);
            $lat_lng = explode(',', $coordinaten);
            $params['facet_value'] = $lat_lng[0];
            $params['facet_display_value'] = $lat_lng[1];
        }
    }
    return $params;
}, 10, 2);

Like this article?

Share on Facebook
Share on Twitter
Share on Linkdin
Share on Pinterest
Author picture

SitiWeb is de expert op het gebied van WordPress. gespecialiseerd in het leveren van maatwerk.

Leave a comment

Eén reactie

  1. Can you give some screenshots of things please? I can’t get the distance to show it just says 0 as a distance but I’ve set the GPS data.

Geef een reactie

Je e-mailadres wordt niet gepubliceerd. Vereiste velden zijn gemarkeerd met *