Frank Vèssia Posted October 20, 2011 Share Posted October 20, 2011 I have a date field in european format d-m-Y. I want to order my "articles" by this field. I cannot use the created built in field because publisher decide the publish date using this field, but it seems doesn't work using sort=pdate pdate is my date field Link to comment Share on other sites More sharing options...
apeisa Posted October 20, 2011 Share Posted October 20, 2011 sort=-pdate should work. If I remember correctly, dates are saved as Unix timestamp on SBM and input format doesn't matter here. Link to comment Share on other sites More sharing options...
Frank Vèssia Posted October 20, 2011 Author Share Posted October 20, 2011 i tried, no luck, strange... Link to comment Share on other sites More sharing options...
ryan Posted October 20, 2011 Share Posted October 20, 2011 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 More sharing options...
apeisa Posted October 20, 2011 Share Posted October 20, 2011 Ah, you probably need to add pdate as autojoin field. It's under advanced tab. Link to comment Share on other sites More sharing options...
ryan Posted October 20, 2011 Share Posted October 20, 2011 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 More sharing options...
Frank Vèssia Posted October 20, 2011 Author Share Posted October 20, 2011 @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 More sharing options...
Adam Kiss Posted October 20, 2011 Share Posted October 20, 2011 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 More sharing options...
Frank Vèssia Posted October 20, 2011 Author Share Posted October 20, 2011 you are right Adamkiss, putting the sort as last item it works... thanks, it's a bug?? Link to comment Share on other sites More sharing options...
ryan Posted October 20, 2011 Share Posted October 20, 2011 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now