• like your ACF-plugin and all the awesome features i see.

    btw: i want to perform a retrieval to the endpoint of OSM – eg like so.



    [out:csv(::id,::type,::lon,::lat,amenity,name,"addr:postcode","addr:city","addr:street","addr:housenumber","contact:website",website,"contact:email")]
    [timeout:600];
    rel[boundary=administrative][admin_level=6][name="München"] -> .city;
    (nwr[amenity=hospital][name](around.city:2000);
    nwr[amenity=school][name](around.city:2000);
    nwr[amenity=church][name](around.city:2000);
    nwr[amenity=childcare][name](around.city:2000);
    nwr[amenity=nursing_home][name](around.city:2000););
    out center;

    well – i could perform this with the following code.




    <?php
    /*
    Plugin Name: ACF Schools Widget
    Description: Displays nearby schools using Overpass Turbo and ACF.
    Version: 1.0
    Author: foo bar
    */

    // Exit if accessed directly
    if (!defined('ABSPATH')) exit;

    // Include ACF
    include_once(plugin_dir_path(__FILE__) . 'acf/acf.php');

    // Register ACF fields
    function register_acf_fields() {
    if (function_exists('acf_add_local_field_group')) {
    acf_add_local_field_group(array(
    'key' => 'group_1',
    'title' => 'Nearby Schools Widget',
    'fields' => array(
    array(
    'key' => 'field_1',
    'label' => 'Latitude',
    'name' => 'latitude',
    'type' => 'number',
    'required' => 1,
    ),
    array(
    'key' => 'field_2',
    'label' => 'Longitude',
    'name' => 'longitude',
    'type' => 'number',
    'required' => 1,
    ),
    array(
    'key' => 'field_3',
    'label' => 'Radius (km)',
    'name' => 'radius',
    'type' => 'number',
    'required' => 1,
    ),
    ),
    'location' => array(
    array(
    array(
    'param' => 'post_type',
    'operator' => '==',
    'value' => 'page',
    ),
    ),
    ),
    ));
    }
    }
    add_action('acf/init', 'register_acf_fields');

    // Enqueue necessary scripts
    function acf_schools_widget_enqueue_scripts() {
    wp_enqueue_script('jquery');
    }
    add_action('wp_enqueue_scripts', 'acf_schools_widget_enqueue_scripts');

    // Shortcode to display schools
    function display_nearby_schools($atts) {
    $latitude = get_field('latitude');
    $longitude = get_field('longitude');
    $radius = get_field('radius');

    if (!$latitude || !$longitude || !$radius) {
    return 'Please provide latitude, longitude, and radius.';
    }

    // Overpass API URL
    $query = '[out:json][timeout:25];(node["amenity"="school"](around:' . ($radius * 1000) . ',' . $latitude . ',' . $longitude . '););out body;>;out skel qt;';
    $url = 'https://overpass-api.de/api/interpreter?data=' . urlencode($query);

    // Fetch data from Overpass API
    $response = wp_remote_get($url);
    if (is_wp_error($response)) {
    return 'Unable to retrieve data.';
    }

    $body = wp_remote_retrieve_body($response);
    $data = json_decode($body, true);

    if (empty($data['elements'])) {
    return 'No schools found in the specified area.';
    }

    // Display data
    $output = '<ul class="nearby-schools">';
    foreach ($data['elements'] as $element) {
    if (isset($element['tags']['name'])) {
    $output .= '<li>';
    $output .= esc_html($element['tags']['name']);
    if (isset($element['tags']['website'])) {
    $output .= ' - <a href="' . esc_url($element['tags']['website']) . '" target="_blank">' . esc_html($element['tags']['website']) . '</a>';
    }
    $output .= '</li>';
    }
    }
    $output .= '</ul>';

    return $output;
    }
    add_shortcode('nearby_schools', 'display_nearby_schools');

    and display this in a widget in WordPress. Well i would like to use your plugin here – to get this done — and to show the results in a little table

  • The topic ‘perform request a overpass-turbo.eu – (API-Frontend) and show results in Table’ is closed to new replies.