Md Mehedi Hasan

wp_localize_script() to Send Data from PHP

function.php

<?php
$launcher_year  = get_post_meta(get_the_ID(), "year", true);
$launcher_month = get_post_meta(get_the_ID(), "month", true);
$launcher_day   = get_post_meta(get_the_ID(), "day", true);

wp_localize_script("main-jquery-js", "datedata", array(
    "year"  => $launcher_year,
    "month" => $launcher_month,
    "day"   => $launcher_day,
));

main.js

var countDown = function () {
    console.log(datedata);
    simplyCountdown('.simply-countdown-one', {
        year: datedata.year,
        month: datedata.month,
        day: datedata.day
    });
};