Skip Navigation

[Resolved] Display more posts where custom date field is around current displayed post

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

Problem:

The essential issue here was that the user had some custom shortcode, however they wanted to use this shortcode to provide a value for a view parameter.

Solution:

In order for custom shortcodes to work in our Views shortcodes you will need to add it to the views third party shortcode arguments in Toolset > Settings > Frontend.

This support ticket is created 5 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.

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

Supporter timezone: America/Jamaica (GMT-05:00)

Tagged: 

This topic contains 4 replies, has 2 voices.

Last updated by romanB-3 5 years, 7 months ago.

Assisted by: Shane.

Author
Posts
#1231601

I have a custom post type called "incident" which a custom date field called "date".

Then on a page I have a view displaying an form in order to edit the most recent "incident" based on the "date" field :

<wpv-loop><div class="row">
	<div class="col-sm-9">[cred_form form="modification-incident" post="[wpv-post-id]"]</div></wpv-loop>

On the right side of this view, I would need to display all "incidents" where the "date" value is between 3 days before and 3 days after the current incident in the loop.

In order to do this, I've created a new view with a custom field filter based on "date" field with settings : "number" / "between" / shortcode attribute "avant" and shortcode attribute "apres".

Then I edit my main view like this :

<wpv-loop><div class="row">
	<div class="col-sm-9">[cred_form form="modification-incident" post="[wpv-post-id]"]</div>
	<div class="col-sm-3">[types field='date' output='raw'][/types]<br>
      avant: [calculate][types field='date' output='raw'][/types]-3*24*60*60[/calculate]<br>
      après: [calculate][types field='date' output='raw'][/types]+3*24*60*60[/calculate]<br>
          <ul>[wpv-view name="volet-lateral-pour-traitement-incidents-importes" avant="[calculate][types field='date' output='raw'][/types]-3*24*60*60[/calculate]" apres="[calculate][types field='date' output='raw'][/types]+3*24*60*60[/calculate]"]</ul></div>
</div>
		</wpv-loop>

But the page displays all "incidents", and doesn't filter results based on the date like it should.

Thank you.

PS : I of course have added the [calculate] shortcode to my functions.php.

#1231631

Shane
Supporter

Languages: English (English )

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

Hi Roman,

As a guide I will be using this ticket here .
https://toolset.com/forums/topic/views-filter-date-by-a-specific-month/#post-953546

However give me some time to write the custom filter for you.

One question you are providing a shortcode from our Types field with the date value correct?

Please let me know.
Thanks,
Shane

#1231632

Shane
Supporter

Languages: English (English )

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

Also could you give me a sample of what these return.

avant: [calculate][types field='date' output='raw'][/types]-3*24*60*60[/calculate]<br>
après: [calculate][types field='date' output='raw'][/types]+3*24*60*60[/calculate]<br>

Thanks,
Shane

#1231633
avant: [calculate][types field='date' output='raw'][/types]-3*24*60*60[/calculate]<br>
après: [calculate][types field='date' output='raw'][/types]+3*24*60*60[/calculate]<br>

returns :

avant: 1545609600<br>
après: 1546128000

When I replace the calculate shortcodes by the calculated values, it all works great :

[wpv-view name='volet-lateral-pour-traitement-incidents-importes' avant='1545609600' apres='1546128000']

But when the shortcode are inside the view attributes, it breaks it all :

[wpv-view name='volet-lateral-pour-traitement-incidents-importes' avant='[calculate][types field="date" output="raw"][/types]-3*24*60*60[/calculate]' apres='[calculate][types field="date" output="raw"][/types]+3*24*60*60[/calculate]']
#1231639

Declaring the shortcode "calculate" in toolset parameters solved the problem....

Thank you.