WordPress.org

Ready to get started?Download WordPress

Forums

Weather Forecast - WP Wunderground
Shortcode with variables for location values not working (3 posts)

  1. kcomphlint
    Member
    Posted 11 months ago #

    I am using WP Wunderground, WP Geolocation JS and PHP Shortcode.

    I am attaching the city and state of the visitor to variables like so:

    $weathercity = do_shortcode('[mmjs-city]');
    $weatherstate = do_shortcode('[mmjs-regionname]');

    I can echo those locations within a page or post using the PHP Shortcode plugin like so:

    [php]
    $weathercity = do_shortcode('[mmjs-city]');
    $weatherstate = do_shortcode('[mmjs-regionname]');
    echo $weathercity .', '.$weatherstate;
    [/php]

    Which essentially renders something like Chicago, Illinois.

    I can echo a shortcode using the PHP Shortcode plugin like so:

    [php]
    $weathercity = do_shortcode('[mmjs-city]');
    $weatherstate = do_shortcode('[mmjs-regionname]');
    echo $weathercity .', '.$weatherstate;
    echo '[forecast location='.$weathercity.', '.$weatherstate.']';
    [/php]

    It will actually spit out the shortcode as :

    [forecast location="Chicago, Illinois"]

    However, if I try to run do_shortcode on the last line like so:

    [php]
    $weathercity = do_shortcode('[mmjs-city]');
    $weatherstate = do_shortcode('[mmjs-regionname]');
    echo $weathercity .', '.$weatherstate;
    echo do_shortcode('[forecast location='.$weathercity.', '.$weatherstate.']');
    [/php]

    The weather does not show up at all. Any ideas on how I can handle this? I really just want to be able to sniff the location of the user and display weather for that location.

    http://wordpress.org/extend/plugins/wunderground/

  2. mkbn
    Member
    Posted 5 months ago #

    looking for same input

  3. Paul Thomson
    Member
    Posted 5 months ago #

    This works for me... have a fiddle, good luck

    <div class="weather">' . do_shortcode("[forecast location='$coordinated' caption=\"6-Day Weather forecast for <b>$ev_location</b> ($coordinated):\" measurement=\'C\' todaylabel=\"Today\" datelabel=\"%%weekday%% <br> date(\'d M \'n\')\" highlow=\'%%high%%&deg;/%%low%%&deg;\' numdays=\"6\" cache=\"True\" iconset=\"Generic\" class=\"weather_table\"]") . '</div>

Reply

You must log in to post.

About this Plugin

About this Topic