Skip Navigation

[Resolved] Using shortcodes to get Monday This Week date

This support ticket is created 5 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 4 replies, has 2 voices.

Last updated by barryG-4 5 years, 9 months ago.

Assisted by: Waqar.

Author
Posts
#1204959

Tell us what you are trying to do?

I have tried hard to research this before bothering you but I cannot find the answer.

THE SET UP
I have two custom taxonomy sets. One being called this week and one next week, each with Monday, Tuesday, Wednesday, Thursday, Friday, Saturday and Sunday as items added to them.

A staff Custom Post Type shows the taxonomies and they are ticked according to what days that member of staff works this week and next week.

I have created views to show separately a list of each staff working on a given day as in the following example for Monday this week:

Select posts with taxonomy:
this week days in one of these: Monday

A page then has a section showing seven rows of staff working on each day of the current week displayed via the view. There is another section which shows seven rows of staff working next week.

At the top of the two sections there is text showing ‘Week Beginning 18th February’ and ‘Week Beginning 25th February’. These dates have to be manually entered each week.

WHAT I'D LIKE TO DO
What I’d like to do is use php or something else, to find this Monday’s date and next Monday’s date which I think can be done using:

<?php
echo strtotime("this Monday"), "\n";
?>

So is it possible to do this within a shortcode somehow so that no-one has to enter the dates manually each week?

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site? hidden link and the section to look at is 'schedule'.

Many thanks,
Barry.

#1205332

Hi Barry,

Thanks for asking! I'd be happy to help.

The support that we provide is limited to Toolset's own features and code, but we do our best to guide in the right direction, whenever possible.

To generate a future date using the PHP code, you can register a custom shortcode that uses a DateTime() object, as shown in this example:
https://stackoverflow.com/questions/1188728/get-the-date-of-next-monday-tuesday-etc

You can use it in your custom shortcode like this:
( ref: https://codex.wordpress.org/Shortcode_API )


add_shortcode('output_monday_date', 'output_monday_date_fn');
function output_monday_date_fn($atts) {
	$week = $atts['week'];

	$req_date = new DateTime();

	if ($week == 'this') {
		$req_date->modify('this monday');

	} elseif ($week == 'next') {
		$req_date->modify('next monday');	
	}

	if(!empty($req_date)) {
		return $req_date->format('d-m-Y');;
	}
}

As a result, [output_monday_date week="this"] and [output_monday_date week="next"], will give you the date of this and next week's Monday, respectively.

For general assistance around PHP and WordPress code, you can consult dedicated and specialist forums like:
https://wordpress.org/support/forums/
https://stackoverflow.com/

regards,
Waqar

#1205491

Hi Waqar,

Thank you so much again that is completely brilliant. I got stuck where to put the code but googled it and added it to the functions.php file and it works.....Finishing my first Toolset based site would not have been. possible without your help.

Many thanks,
Barry.

#1205504

Thanks for the update Barry and glad you found our support useful!

For a new question/concern, you're welcome to open a new ticket - we're here to help!

regards,
Waqar

#1206558

My issue is resolved now. Thank you!