• I have a bunch of HTML which is used to display the weather on my website. On each post, I would like the weather widget to be customized to the location of that post.

    Each post has two meta_key:
    main_point_latitude
    main_point_longitude

    meta_value is number is both cases.

    The widget takes two arguements: data-lat and data-lng (see documentation https://windy.app/widgets)

    Given that I need php to return these meta values, what else do I need to do here? I do not want to edit the main php files, but I’m happy to use something like code snippets, and use a shortcode.

    Currently I have not been successful in using the shortcode via code snippets.

    This is the php that i’ve been using in code snippets:

    $lat = get_post_meta(get_the_ID(), 'main_point_latitude', true);
    $lng = get_post_meta(get_the_ID(), 'main_point_longitude', true);

    This is the rest of the code that I’ve been using in the html editor. I’m not sure how to complete the two missing arguements.

    <div
    data-windywidget="forecast"
    data-thememode="white"
    data-tempunit="F"
    data-lat=
    data-lng=
    data-appid="0fea25fa5677b6078fede48527aa7fdf">
    </div>
    
    <script async="true" data-cfasync="false" type="text/javascript" src="https://windy.app/widgets-code/forecast/windy_forecast_async.js?v1.3.91"></script>
    • This topic was modified 3 years, 2 months ago by sebtaylor55.

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

Viewing 1 replies (of 1 total)
  • Plugin Author Shea Bunge

    (@bungeshea)

    You should be able to achieve this by adding this code as a Content Snippet:

    <div
    	data-windywidget="forecast"
    	data-thememode="white"
    	data-tempunit="F"
    	data-lat="<?php echo esc_attr( get_post_meta( get_the_ID(), 'main_point_latitude', true ) ); ?>"
    	data-lng="<?php echo esc_attr( get_post_meta( get_the_ID(), 'main_point_longitude', true ) ); ?>"
    	data-appid="0fea25fa5677b6078fede48527aa7fdf">
    </div>
    
    <script
    	async
    	data-cfasync="false"
    	type="text/javascript"
    	src="https://windy.app/widgets-code/forecast/windy_forecast_async.js?v1.3.91"
    ></script>
Viewing 1 replies (of 1 total)

The topic ‘Use meta data in html block’ is closed to new replies.