Skip Navigation

[Résolu] Get sticky posts of last 12 hours

Ce fil est résolu. Voici une description du problème et la solution proposée.

Problem:
How to display 12 hours old post

Solution:
You can use views filter hook 'wpv_filter_query' to modify the view query on fly. In this case you need to modify the date_query.

You can find the proposed solution with the following reply:
https://toolset.com/forums/topic/get-sticky-posts-of-last-12-hours/#post-359178

Relevant Documentation:
=> https://toolset.com/documentation/user-guides/views-filters/
=> https://toolset.com/documentation/user-guides/views-filters/wpv_filter_query/

This support ticket is created Il y a 8 années et 2 mois. 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
- 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)

Marqué : 

This topic contains 6 réponses, has 2 voix.

Last updated by stefanoT-2 Il y a 8 années et 2 mois.

Assisted by: Minesh.

Auteur
Publications
#358439

Hi!
I am trying to display the sticky posts of the last 12 hours.

I created my view and set the filter by "post stickness", but I have some problems to set the filter by time.

I set the filter by "Post Date" like this: "Post date is after or equal hour: PAST_ONE(12)" but it does not seems to work. I get only some old posts from August and July, which is totally wrong.

How I must set this filter to make it work correctly?
Thanks.

#358447

Minesh
Supporter

Languages: Anglais (English )

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

Hello. Thank you for contacting the Toolset support.

1)
Could you please send me screenshot of your edit view page's filter section?

2)
Could you please send me debug information that will help us to investigate your issue.
=> https://toolset.com/faq/provide-debug-information-faster-support/

#358591
view-filters.jpg

I sent the debug information and you can see the view filters in the attached image.

The plugin is in italian: "Costante" equals to "Constant" and "PASSATO_UNO" equals to "PAST_ONE".

However, now the problem is a little bit different: the views displays the last 5 sticky posts without taking care of the time it was published.

#358840

Minesh
Supporter

Languages: Anglais (English )

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

Could you please try to select posts whose Published date is after:
year:CURRENT_ONE(), month:CURRENT_ONE(), week:CURRENT_ONE(), hour:PAST_ONE(12)

Does this works as you needed?

#358955

Nope, it doesn't work.

This is my actual situation:
- I set the filter just like you said, except for the number of the hours (just 1 hour for testing purposes)
- Here it's 5 pm, and I have a post published at 4:30 pm which should be displayed in the view

BUT the view doesn't display any posts.

Strange thing is that if I change the condition from "after" to "after or equal to", the view displays posts even older than 1 hour (published at 2:30 pm and even earlier).

Why?

#359178

Minesh
Supporter

Languages: Anglais (English )

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

Please REMOVE publish date filter that you have added to view.

Could you please try to add following code to your current theme's functions.php file

add_filter( 'wpv_filter_query', 'limit_time_on_query', 99, 3 );
function limit_time_on_query($query_args, $view_setting, $view_id) 
{
 if ($view_id == 999)
 {
  $query_args['date_query'] = array(
   array(
    'after' => '12 hours ago'
   )
      );
 }
    return $query_args;
}

Where:
Please change "999" with your original view id.

#359416

Now it works perfectly!

Thanks for the support, however I think this filter should work using the views settings only, without using a custom function.

Hope you fix this soon!

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