Jump to content

Get filtered pages


Sradesign
 Share

Recommended Posts

Hi

I'm trying to find a way to show pages detail based on filtered date for example I want to get the pages that created this week how to achieve this with selector? mind you I'm not looking for past 7 days I want for the current week.

Best Regards,

Ali.M

Link to comment
Share on other sites

If you take a view on what day a week starts on, you can use the PHP function strtotime() to get the timestamp of the last time that day happened and format it using date() to get it as a string for use in your find/filter selector.
 
For example, if you decide a week starts on Monday, then this should get you a value you can use in selectors...

$when = 'Last Monday';
$timestamp = strtotime($when);
$date = date('Y-m-d', $timestamp);
//echo "The date $when was $date\n";

Untested, YMMV.

  • Like 1
Link to comment
Share on other sites

If your week starts on sunday


$d = strtotime("today");

$start_week = strtotime("last sunday midnight",$d);

$end_week = strtotime("next saturday",$d);

$start = date("Y-m-d",$start_week);

$end = date("Y-m-d",$end_week);

and then filter your pages like this:


$results = $pages->find("datefield>=$start_week, datefield<=$end_week");

where datefield is whatever date field you are trying to filter.

  • Like 5
Link to comment
Share on other sites

Since you asked for 'created' you can swap datefield in the example by  @Alxndre'  for created (we also have 'published')

Yup, just like that. :)

If your week starts on sunday

$d = strtotime("today");
$start_week = strtotime("last sunday midnight",$d);
$end_week = strtotime("next saturday",$d);
$start = date("Y-m-d",$start_week); 
$end = date("Y-m-d",$end_week);  
and then filter your pages like this:
$results = $pages->find("datefield>=$start_week, datefield<=$end_week");
where datefield is whatever date field you are trying to filter.

Thank you all I did it like below :

// Today Registrations
$todaydate = strtotime("today");
$today_registrations = $users->count('roles=member,created>='.$todaydate);

// This Week Registrations		
$weekdate = strtotime("last sunday midnight",$todaydate);
$week_registrations = $users->count('roles=member,created>='.$weekdate);
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...