Skip Navigation

[Resolved] Conditional to determine current User’s horoscope sign

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to use a conditional to display different content based on the current User's horoscope sign, based on a User birthdate custom field.

Solution:
Inside a View of Users, to access the current logged-in User's information you must use a nested View of Users. Create a new View of Users, filtered by specific Users, using a shortcode attribute filter "users". See the attached screenshot. Use the wpv-current-user shortcode to pass the current User's ID into the nested View filter. Here is an example using your portrait View:

<wpv-loop>
[wpv-view name="nested-view-slug" users="[wpv-current-user info='id']"]
</wpv-loop>

Add the following custom shortcode:

add_shortcode( 'is_month_day_between', 'is_month_day_between_func');
function is_month_day_between_func($atts)
{
  // shortcode attributes for timestamps start time, end time, and test time
  $start = $atts['start'];
  $end = $atts['end'];
  $test = $atts['test'];
  $result = 0;
  // make new timestamps using the current Year so we can compare
  $modStart = strtotime(date('d F, ', $start) . date('Y'));
  $modEnd = strtotime(date('d F, ', $end) . date('Y'));
  $modTest = strtotime(date('d F, ', $test) . date('Y'));
  // compare and return 0 or 1 if test is between start and end
  if(($modStart <= $modTest) && ($modTest <= $modEnd)){
    $result = 1;
  }
  return $result;
}

Register 'is_month_day_between' in Toolset > Settings > 3rd party Shortcode Arguments, then you can use it in a conditional that tests the User's birthday against a known range of dates.

[wpv-conditional if="([is_month_day_between start='1498247543' end='1440359543' test='[wpv-post-field name='wpcf-date-de-naissance']'] eq '1')"]  This month and day is between start and end
[/wpv-conditional]
[wpv-conditional if="([is_month_day_between start='1498247543' end='1440359543' test='[wpv-post-field name='wpcf-yourdatefieldslug']'] eq '1')" evaluate="false"]  This month and day is not between start and end
[/wpv-conditional]

To account for the first sign, which spans two years, you must use two conditionals that test if the date is between Dec 21 and Dec 31, or if the date is between Jan 1 and Jan 21.

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

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Tagged: 

This topic contains 19 replies, has 3 voices.

Last updated by Pat 6 years, 10 months ago.

Assisted by: Christian Cox.

Author
Posts
#606542

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Pat,

Christian is currently on holidays but will be back tomorrow to assist further with this.

Thanks,
Shane

#606847

Okay I understood from your earlier comment:
What I want is to compare if a date is between D1D1/M1M1 and D2D2/M2M2. Year is not important.
You want to compare dates without Year. So in your example, we are testing these dates:
Jan 21 (end)
Dec 21 (start)
Jan 1 (test)

If Year is not important, then nothing will ever match, because December 21 is after January 21 in the same calendar year. So the "start" date occurs after the "end" date - that's not possible and should never be expected to result in a positive conditional. What have I misunderstood? Please explain in more detail what you mean by "Year is not important" by providing some examples. Thanks!

#606858

Pat

Hi Christian,

What I'm searching here, is to make an astrological site. This means I need to display, thanks to the user birthdate, the informations concerning his astrological sign.
What you have proposed seems to work fine for standard signs (those with end and start date in the same year). The only issue is for the first sign, which is between Dec, 23 to Jan 23
In my first test, I was thinking to have taken that into consideration as I placed the following dates :
945817200 = Tue, 21 Dec 1999
948495599 = Fri, 21 Jan 2000

So normally, the start date is before the end date and this should work. But this is not the case.
Any idea?
Pat

#606922

I can't think of an easy way to do that in one conditional - the logic is fairly complex. However, I think you could do it with a combination of two conditionals using the shortcode we already created. You could test if the date is between Dec 21 and Dec 31 OR if the date is between Jan 1 and Jan 21. If either is true, you know the date is in the first sign.

#606990

Pat

Hi Christian,

Thanks for your support.
I'm OK with your last proposal and I will implement it quickly.
I understand it is difficult to manage this kind of conditional statement within Views !
Regards
Pat