File: /www/wwwroot/biographybirthday.com/wp-content/themes/bio/metafield-variable.php
<?php
/**
* Variable declaration for meta field
*
*/
// function to get value for bography metafield
function metaField($meta_field) {
$meta_value = get_post_meta( get_the_ID(), $meta_field , true );
return $meta_value;
}
function metaFieldValue($meta_field) {
echo get_post_meta( get_the_ID(), $meta_field , true );
}
// function for married status
function marriedStats($marriedstat) {
$marriedData = '';
$marriedstatus = get_post_meta( get_the_ID(), $marriedstat , true );
if( $marriedstatus == 'married' ) {
$marriedData = 'Married';
} elseif( $marriedstatus == 'single' ) {
$marriedData = 'Single';
} elseif( $marriedstatus == 'divorce' ) {
$marriedData = 'Divorce';
} elseif( $marriedstatus == 'not_identified' ) {
$marriedData = 'Not Known';
} elseif( $marriedstatus == 'in-relation' ) {
$marriedData = 'In Relation';
} elseif( $marriedstatus == 'widow' ) {
$marriedData = 'Widow';
}
return $marriedData;
}
// function for married status
function marriedStatsurl($marriedstat) {
// $marriedData = '';
$marriedstatusurl = get_post_meta( get_the_ID(), $marriedstat , true );
return $marriedstatusurl;
}
// function to find gender
function genderStat($gender) {
$genderStats = get_post_meta( get_the_ID(), $gender , true );
if( $genderStats == 'undefined' ) {
echo '';
} elseif( $genderStats == 'male' ) {
echo 'Male';
} elseif( $genderStats == 'female' ) {
echo 'Female';
}
}
// function to find affair
function affairStat($affair) {
$genderStats = get_post_meta( get_the_ID(), $affair , true );
if( $genderStats == 'not_identified' ) {
echo '';
} elseif( $genderStats == '1' ) {
echo '<tr>
<th>Is ' . get_the_title() . ' having any relationship affair ?: </th>
<td> Yes </td>
</tr>';
} elseif( $genderStats == '0' ) {
echo '<tr>
<th>Is ' . get_the_title() . ' having any relationship affair ?: </th>
<td> No </td>
</tr>';
}
}
function lesbianGayStat($lesbian_gay) {
$gender = get_post_meta( get_the_ID(), 'marriedBiography_gender' , true );
$gender_value = '';
if( $gender == 'undefined' ) {
$gender_value = '';
} elseif( $gender == 'male' ) {
$gender_value = 'gay';
} elseif( $gender == 'female' ) {
$gender_value = 'lesbian';
}
$genderStats = get_post_meta( get_the_ID(), $lesbian_gay , true );
if( $genderStats == 'not_identified' || $gender_value == '') {
echo '';
} elseif( $genderStats == '1' ) {
echo '<tr>
<th>Is ' . get_the_title() . ' '.$gender_value.' ?: </th>
<td> Yes </td>
</tr>';
} elseif( $genderStats == '0' ) {
echo '<tr>
<th>Is ' . get_the_title() .' '. $gender_value.' ?: </th>
<td> No </td>
</tr>';
}
}
function birthDate($meta_field) {
$bioDob = get_post_meta( get_the_ID(), $meta_field , true );
$dob_f = date("d-m-Y", strtotime($bioDob));
return $dob_f;
}
function formatymd($meta_field) {
$bioDob = get_post_meta( get_the_ID(), $meta_field , true );
$birthdate = date("Y-m-d", strtotime($bioDob));
return $birthdate;
}
function calculateAge($dob){
$date = new DateTime($dob);
$diff = $date->diff(new DateTime());
// echo $diff->y . ' years ' . ($diff->m) . ' months';
return $diff->y . ' years';
}
// function calculateAge($dob)
// {
// $localtime = getdate();
// $today = $localtime['mday']."-".$localtime['mon']."-".$localtime['year'];
// $dob_a = explode("-", $dob);
// $today_a = explode("-", $today);
// $dob_d = $dob_a[0];
// $dob_m = $dob_a[1];
// $dob_y = $dob_a[2];
// $today_d = $today_a[0];
// $today_m = $today_a[1];
// $today_y = $today_a[2];
// $years = $today_y - $dob_y;
// $months = $today_m - $dob_m;
// if ($today_m.$today_d < $dob_m.$dob_d)
// {
// $years--;
// $months = 12 + $today_m - $dob_m;
// }
// if ($today_d < $dob_d)
// {
// $months--;
// }
// $firstMonths=array(1,3,5,7,8,10,12);
// $secondMonths=array(4,6,9,11);
// $thirdMonths=array(2);
// if($today_m - $dob_m == 1)
// {
// if(in_array($dob_m, $firstMonths))
// {
// array_push($firstMonths, 0);
// }
// elseif(in_array($dob_m, $secondMonths))
// {
// array_push($secondMonths, 0);
// }elseif(in_array($dob_m, $thirdMonths))
// {
// array_push($thirdMonths, 0);
// }
// }
// echo $years . ' years ' . $months . ' months';
// }
// function to find zodic sign
function zodiac($birthdate) {
list ($year, $month, $day) = explode ("-", $birthdate);
$zodiac = getZodiac($month, $day);
return $zodiac;
return '<a href="'. get_home_url() .'/horoscope/?horoscope='.$zodiac.'">' . $zodiac .'</a>';
}
// function to convert birthday like November 27, 1993 with link on it
function bday($param1) {
$monthName = "";
$bday = explode('-', $param1);
$year = $bday[0];
$month = $bday[1];
$day = $bday[2];
if( $month==1 ) { $monthName = "January "; }
elseif( $month==2 ) { $monthName = "February "; }
elseif( $month==3 ) { $monthName = "March "; }
elseif( $month==4 ) { $monthName = "April "; }
elseif( $month==5 ) { $monthName = "May "; }
elseif( $month==6 ) { $monthName = "June "; }
elseif( $month==7 ) { $monthName = "July "; }
elseif( $month==8 ) { $monthName = "August "; }
elseif( $month==9 ) { $monthName = "September "; }
elseif( $month==10 ) { $monthName = "October "; }
elseif( $month==11 ) { $monthName = "November "; }
elseif( $month==12 ) { $monthName = "December "; }
echo '<a href="'. get_home_url() .'/birthday/?date='.$month. '-' .$day.'">' . $monthName . $day . '</a>, <a href="'. get_home_url() .'/birthyear/?date='.$year.'">' . $year . '</a>';
}
function marrieddate($param1) {
$monthName = "";
$marrieddate = explode('-', $param1);
$year = $marrieddate[0];
$month = $marrieddate[1];
$day = $marrieddate[2];
if( $month==1 ) { $monthName = "January "; }
elseif( $month==2 ) { $monthName = "February "; }
elseif( $month==3 ) { $monthName = "March "; }
elseif( $month==4 ) { $monthName = "April "; }
elseif( $month==5 ) { $monthName = "May "; }
elseif( $month==6 ) { $monthName = "June "; }
elseif( $month==7 ) { $monthName = "July "; }
elseif( $month==8 ) { $monthName = "August "; }
elseif( $month==9 ) { $monthName = "September "; }
elseif( $month==10 ) { $monthName = "October "; }
elseif( $month==11 ) { $monthName = "November "; }
elseif( $month==12 ) { $monthName = "December "; }
echo '<a href="'. get_home_url() .'/married/?date='.$month. '-' .$day.'">' . $monthName . $day . '</a>, <a href="'. get_home_url() .'/married-year/?date='.$year.'">' . $year . '</a>';
}
function gossiobio_posted_on() {
$time_string = '<time class="entry-date published updated" datetime="%1$s">%2$s</time>';
if ( get_the_time( 'U' ) !== get_the_modified_time( 'U' ) ) {
$time_string = '<time class="entry-date published" datetime="%1$s">%2$s</time><time class="updated" datetime="%3$s"><span class="posted-on"> / Last Modified %4$s</span></time>';
}
$time_string = sprintf( $time_string,
esc_attr( get_the_date( 'c' ) ),
esc_html( get_the_date() ),
esc_attr( get_the_modified_date( 'c' ) ),
esc_html( get_the_modified_date() )
);
$posted_on = sprintf(
esc_html_x( 'Posted on %s', 'post date', 'mbiography' ), $time_string );
$byline = sprintf(
esc_html_x( 'Posted by %s ', 'post author', 'mbiography' ),
'<span class="author vcard">Gossiobio</span>'
);
// echo '<span class="byline"> ' . $byline . '</span>';
echo '<span class="posted-on">' . $posted_on . '</span>';
}
function ordinal($num)
{
$last=substr($num,-1);
if( $last>3 or
$last==0 or
( $num >= 11 and $num <= 19 ) )
{
$ext='th';
}
else if( $last==3 )
{
$ext='rd';
}
else if( $last==2 )
{
$ext='nd';
}
else
{
$ext='st';
}
return $num.$ext;
}
function getZodiac($month, $day){
$zodiac = '';
if ( ( $month == 3 && $day > 20 ) || ( $month == 4 && $day < 20 ) ) { $zodiac = "Aries"; }
elseif ( ( $month == 4 && $day > 19 ) || ( $month == 5 && $day < 21 ) ) { $zodiac = "Taurus"; }
elseif ( ( $month == 5 && $day > 20 ) || ( $month == 6 && $day < 21 ) ) { $zodiac = "Gemini"; }
elseif ( ( $month == 6 && $day > 20 ) || ( $month == 7 && $day < 23 ) ) { $zodiac = "Cancer"; }
elseif ( ( $month == 7 && $day > 22 ) || ( $month == 8 && $day < 23 ) ) { $zodiac = "Leo"; }
elseif ( ( $month == 8 && $day > 22 ) || ( $month == 9 && $day < 23 ) ) { $zodiac = "Virgo"; }
elseif ( ( $month == 9 && $day > 22 ) || ( $month == 10 && $day < 23 ) ) { $zodiac = "Libra"; }
elseif ( ( $month == 10 && $day > 22 ) || ( $month == 11 && $day < 22 ) ) { $zodiac = "Scorpio"; }
elseif ( ( $month == 11 && $day > 21 ) || ( $month == 12 && $day < 22 ) ) { $zodiac = "Sagittarius"; }
elseif ( ( $month == 12 && $day > 21 ) || ( $month == 1 && $day < 20 ) ) { $zodiac = "Capricorn"; }
elseif ( ( $month == 1 && $day > 19 ) || ( $month == 2 && $day < 19 ) ) { $zodiac = "Aquarius"; }
elseif ( ( $month == 2 && $day > 18 ) || ( $month == 3 && $day < 21 ) ) { $zodiac = "Pisces"; }
return $zodiac;
}
function calculateLuckyNumber($year, $month, $day){
return sumDigits(sumDigits($year) + sumDigits($month) + sumDigits($day));
}
function sumDigits($num) {
$num = strval($num);
$sum = 0;
for ($i = 0; $i < strlen($num); $i++){
$sum += $num[$i];
}
return $sum;
}
function luckyStone($month, $day) {
$horoscope = getZodiac($month, $day);
$stones = array(
'Aries' => 'Diamond',
'Taurus' => 'Emerald',
'Gemini' => 'Agate',
'Cancer' => 'Moonstone',
'Leo' => 'Ruby',
'Virgo' => 'Sapphire',
'Libra' => 'Peridot',
'Scorpio' => 'Garnet',
'Sagittarius' => 'Turquoise',
'Capricorn' => 'Topaz',
'Aquarius' => 'Amethyst',
'Pisces' => 'Aquamarine',
);
return $stones[$horoscope];
}
function luckyColor($month, $day) {
$horoscope = getZodiac($month, $day);
$colors = array(
'Aries' => 'Red',
'Taurus' => 'Green',
'Gemini' => 'Yellow',
'Cancer' => 'Silver',
'Leo' => 'Gold',
'Virgo' => 'Green',
'Libra' => 'Blue',
'Scorpio' => 'Purple',
'Sagittarius' => 'Orange',
'Capricorn' => 'Brown',
'Aquarius' => 'Turquoise',
'Pisces' => 'Sea Green',
);
return $colors[$horoscope];
}
function bestMatches($month, $day) {
$horoscope = getZodiac($month, $day);
$bestMatche = array(
'Aries' => 'Leo',
'Taurus' => 'Virgo, Cancer, Capricorn',
'Gemini' => 'Leo, Aquarius, Libra',
'Cancer' => 'Taurus, Pisces, Scorpio',
'Leo' => 'Sagittarius, Gemini, Aries',
'Virgo' => 'Taurus, Capricorn',
'Libra' => 'Gemini',
'Scorpio' => 'Capricorn, Cancer, Pisces',
'Sagittarius' => 'Leo, Aquarius',
'Capricorn' => 'Scorpio, Virgo, Taurus',
'Aquarius' => 'Aquarius, Gemini, Sagittarius',
'Pisces' => 'Cancer, Scorpio',
);
return $bestMatche[$horoscope];
}