Jump to content

Order by custom date


Frank Vèssia
 Share

Recommended Posts

Is 'pdate' actually a 'date' fieldtype? (as opposed to a text fieldtype)?

Antti is correct that the date input/output format doesn't matter here because dates are stored (and sorted) as unix timestamps.

Assuming it's date fieldtype, can you post a larger portion of the code where you load these pages so we can see the full context?

Link to comment
Share on other sites

Autojoin is only necessary for fields that you want to have pages automatically sort by (i.e. be selectable from the pageedit 'children' tab for automatic sorting). But autojoin shouldn't be necessary for API usage. At some point I should be able to get rid of the autojoin requirement for automatic sorting too.

Link to comment
Share on other sites

@Ryan: yes pdate is date fieldtype.

function listVideo($sort="sort=-pdate",$limit=",limit=20",$cats="",$id=""){

$pages= wire('pages');

$today = strtotime(date('d-m-Y')); 

$videos=$pages->get(1006)->children("$sort$limit$published$cats$id,published=1,pdate<=$today");
foreach($videos as $video){
	$new = "";
	$vidtime = $video->pdate;
	$curtime = date("d-m-Y"); $yesterday = date("d-m-Y", strtotime("yesterday"));
	if ($vidtime==$curtime || $vidtime==$yesterday){
		$new = "<div class='newvid'><span class='label success'>Nuovo</span></div>";
	}
	$thumb = $video->videothumb->first()->size(210,118)->url;
	$totalthumbs = count($video->videothumb);
	if ($totalthumbs>1){
		foreach ($video->videothumb as $tempthumb){ $thumbtemp=$tempthumb->size(210,118)->url; }
		$vidid = "id='{$video->id}'";
	}else{
		$vidid = "id=''";
	}
	$videotitle = ucfirst(substr($video->title,0,43));
	echo "
	<div class='blockvideo'>
		{$new}
		<div class='videotitleblock'>{$videotitle}</div>
		<a href='{$video->url}' class='video'>
			<img class='thumbnail' src='{$thumb}' {$vidid} alt='{$video->title}'>
		</a>
		<div class='fake'><img class='fakethumb'  src='{$thumb}' ></div>
		<div class='videostatblock'>Visite: <span class='visits'>{$video->pageviews}</span> | ".strftime("%d %B %Y",strtotime($video->pdate))."<span class='duration'>{$video->duration}</span></div>
	</div>
	";	
} 
}

Link to comment
Share on other sites

Not to brag, but you seem to switch from arguments, where ',' is needed (limit, cats, id) to arguments, where it shoudln't be... do you really want it that way?

Other than that, I would try putting the sort as last item in the call, or switch from get()->children() to find(). This might or might not be bug, so we'll see where the error is.

Link to comment
Share on other sites

It shouldn't matter where the sort is placed. I have a feeling there's a missing comma in your selector string, because that would make it appear that moving it to the end fixed it (since you don't need a comma at the end). One way to tell for sure would be to echo your selector string to see what is getting sent to PW:

echo "$sort$limit$published$cats$id,published=1,pdate<=$today"; 
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...