Skip Navigation

[Closed] Query filter "THIS_WEEK", "FUTURE_WEEK" alternative

This support ticket is created 4 years, 5 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
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)

This topic contains 3 replies, has 2 voices.

Last updated by Christian Cox 4 years, 5 months ago.

Assisted by: Christian Cox.

Author
Posts
#1687447

I want query filter by date field, between "this week" to "future week(1)" .
And in other view "future week(1)" to "future week(2)" etc...
Not "today" to "future_day(7)"!!!
Week Starts On Thursday in my WP settings. (cinema program change day)

Any idea or custom shortcode ?

#1688153
Screen Shot 2020-07-05 at 3.22.43 PM.png

I think you need to set up your Query Filter to filter by custom field date between two shortcode attributes (see the attachment). Then you need a custom shortcode that will return the Unix timestamp at 0:00 on the most recent Thursday. You should be able to pass a shortcode argument into the custom shortcode that allows you to set the number of weeks from now, so you can get the timestamp for this Thursday, next week Thursday (1), the following week Thursday (2), the following week Thursday (3), and so on. So the shortcode must look something like this:

[ts-thursday index="0"][/ts-thursday]

The custom shortcode must return the Unix timestamp at 0:00 (12:00 am) on the most recent Thursday (currently that would be 1593648000). If you pass in 1, it will return the Unix timestamp at 0:00 on the next possible Thursday (currently that would be 1594252800). If you pass in 2, it will return the following Thursday ( currently 1594857600 ), and so on. You will register this shortcode in Toolset > Settings > Front-end Content > 3rd-party shortcode arguments. Then you can use it in the View's shortcode attributes like this:

Films this week:
[wpv-view name="Your View Name" start="[ts-thursday index='0'][/ts-thursday]" end="[ts-thursday index='1'][/ts-thursday]"]

Films next week:
[wpv-view name="Your View Name" start="[ts-thursday index='1'][/ts-thursday]" end="[ts-thursday index='2'][/ts-thursday]"]

Films in two weeks:
[wpv-view name="Your View Name" start="[ts-thursday index='2'][/ts-thursday]" end="[ts-thursday index='3'][/ts-thursday]"]

Will this setup work for your project requirements? If not, please provide more details.

#1691151
FireShot Capture 047 - - Cinemis - dev.elektroger.hu.png
FireShot Capture 043 - Edit Oldal ‹ Cinemis — WordPress - dev.elektroger.hu.png
FireShot Capture 040 - Edit View ‹ Cinemis — WordPress - dev.elektroger.hu.png
FireShot Capture 035 - Settings ‹ Cinemis — WordPress - dev.elektroger.hu.png

I registered the shortcode.
I created a query filter.
I use it in the View's shortcode attributes but the result is not good...
(see attachments)

Simple [wpv-view name="heti-bontas"] code is tested... working

Where did I go wrong?

#1692055

Right, it's not a complete solution - there is no ts-thursday shortcode unless you create one. I suspect you did not create a ts-thursday shortcode. I didn't create one in my example code, I was giving you some ideas you could use in your own custom solution. If you want to use the code I provided as-is, you must also create a custom shortcode that calculates a timestamp for Thursday at 00:00, using the "index" shortcode attribute, and returns that timestamp value. Save that code in your child theme's functions.php file, or in a new snippet in Toolset > Settings > Custom Code. Here is the template you can use for creating the custom shortcode ts-thursday. Add your custom code after the comments in this template to calculate the correct timestamp value.

add_shortcode( 'ts-thursday', 'ts_thursday_func');
function ts_thursday_func( $atts, $content ) {
  $atts = shortcode_atts( array(
    'index' => 0
  ), $atts );
  $week_index = $atts['index'];
  $timestamp = 0;
  
  // your custom code here should calculate the correct value for $timestamp
  // $week_index will default to 0 unless the User provides one in the shortcode: $week_index
  
  return $timestamp;
}

The topic ‘[Closed] Query filter "THIS_WEEK", "FUTURE_WEEK" alternative’ is closed to new replies.