Aron
Aron

Reputation: 183

Echo every third Thursday starting 3 March 2016

Im developing a website for a company using wordpress

They have a board meeting every 3rd Thursday starting 3 March 2016

Im trying to create a shortcode

I want to echo when the next meeting will occur.

This is what ive got so far, but that just isnt correct.

// ECHO next board_meeting - Use [next_board_meeting]
add_shortcode( 'next_board_meeting', 'next_board_meeting_shortcode' );
function next_board_meeting_shortcode( $str ) {

echo date_i18n('l j F', strtotime('next thursday +2 week'));

}

I've been searching the web for something like this , but here I am, asking for your help.

Is there a simple way to do this , or do I need to create a complex php script ?

Bear in mind, I just learned how to do simple tasks in php.

Upvotes: 3

Views: 189

Answers (2)

benedikt
benedikt

Reputation: 1989

Should work with this simple shortcode:

add_shortcode( 'next_board_meeting', 'next_board_meeting_shortcode' );

function next_board_meeting_shortcode( $str ) {

  if(strtotime("3 thursday", strtotime(date('Y-m-01 00:00:00'))) > time())
    echo date('Y-m-d', strtotime("3 thursday", strtotime(date('Y-m-01 00:00:00'))));
  else
    echo date('Y-m-d', strtotime("3 thursday", strtotime("next month", strtotime(date('Y-m-01 00:00:00')))));

}

Demo: https://eval.in/530446

Upvotes: 0

Prakash Rao
Prakash Rao

Reputation: 2398

This code will get you third Thursday of current month ..

If the current date has passed the 3rd Thurs then It will show 3rd Thurs of next month.. If current Month is December and has passed 3rd Thurs then it will show 3rd Thurs in next year in Jan

<?php
$current_date = strtotime(date("d.m.Y"));

//$final = date("Y-m-d", strtotime("+1 month", $time));

$FullMonth = date('F',$current_date);
$FullYear = date('Y',$current_date);
$Third_Thus = date('d F Y', strtotime('third thursday of '.$FullMonth.' '.$FullYear));
$ThirdThus_tmstamp = strtotime($Third_Thus);
if($current_date <= $ThirdThus_tmstamp){
    echo date('d F Y', strtotime('third thursday of '.$FullMonth.' '.$FullYear));
}
else{
    if($FullMonth != 'December'){
        $FullMonth = date('F',strtotime("+1 month", $current_date));
        $FullYear = date('Y',$current_date);
    } else{
        $Next_Year = strtotime("+1 year", $current_date);
        $FullYear = date('Y',$Next_Year);
        $FullMonth = date('F',strtotime("+1 month", $Next_Year));
    }
    echo date('d F Y', strtotime('third thursday of '.$FullMonth.' '.$FullYear));
}?>

This will show only one 3rd Thurs of either Current Month or Next Month depending on the current date.. If you want the 3rd Thurs of next 2-3 month then you can make some changes I guess now !!!

Upvotes: 7

Related Questions