Skip Navigation

[Resolved] Filter by Month and Day

This support ticket is created 8 years, 7 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.

Our next available supporter will start replying to tickets in about 8.88 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 6 replies, has 2 voices.

Last updated by Minesh 8 years, 7 months ago.

Assisted by: Minesh.

Author
Posts
#336124

Hello,

I wonder if anyone can help with a challenge involving Views and a Types custom field for dates.

I have a custom post type for people. Within that type, there is a custom field for an anniversary date. It is a date field within Types.

Ideally, I would like to have a View that displays the people whose anniversaries we are celebrating today. Essentially, I'm trying to get Views to filter by comparing the Types date (month and day only) to the present month and day.

I was able to follow the instructions on the "Filtering by Dates" page to make posts appear if the anniversary date and today were an EXACT match (including year), but so far, no luck in getting it to ignore the year and compare only month and day.

Any suggestions?

Thank you kindly.

#336171

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

As I understand you are looking to compare only month and date regardless of year? If yes:

-- Please share a link of the page where you have added your views.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#336248

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Sorry for confusion:

Could you please confirm this:
As I understand you are looking to compare only month and date regardless of year?

#336268

Yes, exactly. I am trying to compare the Types date field (month and day only) to the current month and day.

#336365

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

1)
I've added following custom shortcode to your current theme's functions.php file.

add_shortcode('check_date_shortcode', 'func_check_date_shortcode');
function func_check_date_shortcode() {
global $post;

$val = get_post_meta( $post->ID, 'wpcf-ordination', true );
$mon = date('n',$val);

$day = date('j',$val);

if($mon == date('n') and $day == date('j',time()))
	return 1;
else
	return 0;
}

2)
Modified your view's template as given under:

[wpv-conditional if="( '[check_date_shortcode]' eq '1' )"]
<p>[wpv-post-title]<br />
[types field="ordination"][/types]<br />
  [types field="email-address"][/types]</p>
[/wpv-conditional]

3)
Added custom shortcode name "check_date_shortcode" to:
=> Views => Settings => Compatibility => Third-party shortcode arguments

Hope this resolves your issue.

#336367

Wow, that seems like a brilliant solution. Am I right to understand that the shortcode gets the date field from the post, parses out the month and day, and then returns a 1 (true) or 0 (false). The view then evaluates whether we have a true or false and displays the appropriate post?

#336408

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Yes, your understanding is perfect 🙂

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.