• Resolved chaosad2

    (@chaosad2)


    Hi,
    Thanks for your job.

    I created a website showing gpx tracks on leaflet.
    I can easily show on each page a track using shortcode, no problem.

    -> [elevation gpx=”https://trackserver.mymaps.fr/wp-content/uploads/gpx/rouvray_01.gpx”%5D

    But is it possible to use an imported file downloaded in ACF (advanced custom fields), and use this file address directly in leaflet shortcode ?

    Shortcode would be included in a widget shown on each page, and would show gpx file map automatically.

    If it’s not possible, is there another easy solution to download a gpx file and show it automatically on a leaflet map ?

    Thanks,

    The page I need help with: [log in to see the link]

Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author hupe13

    (@hupe13)

    Sorry, I don’t know ACF.
    Raruto, the author of leaflet-elevation, which I’m using, has an example. Is this what you want?

    Thread Starter chaosad2

    (@chaosad2)

    Thanks for your answer.
    Yes, I know raruto, it works fine.
    Since yesterday, I changed some things on my website.
    I added code in function.php. Now :
    1) GPX file is added in each article as a custom field with ACF.
    2) I can include ACF file field adress automatically in a specific generated shortcode, using WP-GPX-Maps.
    But I just have a problem, shortcode, added in a widget zone (using shortcode widget), is shown as text, and I can’t see map.
    For example, I can see [sgpx gpx=”/wp-content/uploads/gpx/00_gtm_integral.gpx”], but not the map itself. ??

    Plugin Author hupe13

    (@hupe13)

    Which shortcode you are mean: elevation or sgpx? sgpx is from WP GPX Maps.
    Extensions for Leaflet Map has an option to migrate, but there is a bug in the actual version. I just updated the Github version.
    But it is better to use elevation as long as Bastianon does not update WP GPX Maps.

    Thread Starter chaosad2

    (@chaosad2)

    I tried both of them.
    SGPX shortcode seems to work on my website, elevation shortcode too (I tried both of them).
    My actual problem :

    This code create a shortcode, showing AGGPX shortcode with ACF file name :

    // Get the GPX URL and tranform into a valid shortcode for the 'WP-GPX-Maps' plugin
    function transform_GPX_URL_into_shortcode() {
    
      global $post;
        
      // Get URL from ACF 'fichier_gpx' field
      $url = get_field('fichier_gpx', $post->ID)['url'];
    
      // Keep only the folder name, without the domain
      $url = substr($url,strpos($url,'/wp-content'));
    
      // Add info to create the shortcode and return the url string
      return $url = '[sgpx gpx="' . $url . '"]';
    }
    add_shortcode('carte','transform_GPX_URL_into_shortcode');

    But when I add [carte] in a shortcode widget, it writes (perfectly !) AGGPX shortcode text, but don’t show the map.

    I don’t know why… ??

    • This reply was modified 2 years, 7 months ago by chaosad2.
    • This reply was modified 2 years, 7 months ago by chaosad2.
    Plugin Author hupe13

    (@hupe13)

    Try return $url = do_shortcode('[sgpx gpx="' . $url . '"]');

    Thread Starter chaosad2

    (@chaosad2)

    Sorry, it doesn’t work :

    Parse error: syntax error, unexpected ‘&’ in /homepages/38/d224481250/htdocs/trackserver/wp-content/themes/bam-theme-enfant-creation-new-slang-1660112514/functions.php on line 71

    It seems to be the first “&”, just after “do_shortcode(“.

    Plugin Author hupe13

    (@hupe13)

    $my_shortcode = '[sgpx gpx="' . $url . '"]';
    return do_shortcode($my_shortcode);
    Thread Starter chaosad2

    (@chaosad2)

    Hi,
    Sorry, I didn’t see your answer.
    Thanks, it works perfectly !

    Plugin Author hupe13

    (@hupe13)

    Extensions for Leaflet Map has an option to migrate, but there is a bug in the actual version. I just updated the Github version.

    The bug is fixed now.
    I am glad that I could help.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘File name / CAF’ is closed to new replies.