for a sort by date you can sort by IDs
sort()
original: plugins/wp-favorite-posts/wpfp-page-template.php
——————-
line16: if ($favorite_post_ids):
line17: foreach ($favorite_post_ids as $post_id) {
line:18: $p = get_post($post_id);
etc.
——————-
the same with “sort()”:
——————-
line16: if ($favorite_post_ids):
line17: sort($favorite_post_ids);
line18: foreach ($favorite_post_ids as $post_id) {
line:19: $p = get_post($post_id);
etc.
——————-
Thread Starter
Colir
(@colir)
yes thanks,
this work great.
In the same way do you have an idea to sort this listing by ‘title’ ?
thanks a lot
Thread Starter
Colir
(@colir)
hi. thanks for your help.
In fact, with the help of a developper,
here is 3 differents sorting, base on ‘added date to favorite’, ‘title’, and ‘rating'(need post-rating plugin)
if ($favorite_post_ids):
$i=0;
if($_GET['orderby']=='date' || !isset($_GET['orderby'])){
$favorite_post_ids = array_reverse($favorite_post_ids);
}
if($_GET['orderby']=='title'){
$post_title_tab = array();
foreach ($favorite_post_ids as $post_id) {
$post_info = get_post($post_id);
$post_title_tab[$post_info->post_title] = $post_id;
}
ksort($post_title_tab);
unset($favorite_post_ids);
foreach ($post_title_tab as $title=>$id) {
$favorite_post_ids[] = $id;
}
}
if($_GET['r_sortby']=='highest_rated'){
$post_rating_tab = array();
foreach ($favorite_post_ids as $post_id) {
$post_info = get_post($post_id);
$post_rating_tab[get_post_meta($post_id, 'ratings_average', true)] = $post_id;
}
krsort($post_rating_tab);
unset($favorite_post_ids);
foreach ($post_rating_tab as $rate=>$id) {
$favorite_post_ids[] = $id;
}
}
// use $favorite_post_ids to populate new array(ID => title)
if ($favorite_post_ids):
foreach ($favorite_post_ids as $post_id) {
$p = get_post($post_id);
$favorite_post_by_title[$post_id] = $p->post_title; // new array
}
// sort by title and maintain index association [ natcasesort() ]
natcasesort($favorite_post_by_title);
// and then loop as usual using index as $post_id
foreach ($favorite_post_by_title as $post_id => $title) {
$p = get_post($post_id);
// etc.
}
note: you have get_post() twice, not good for performance, but it work
natcasesort() vs ksort() ?? need some test π
I’m a little lost as to where to put this bit of code, and how to call it up.
Im also a little lost as to where to put the code, am keen to sort them!
Can anyone advise how to sort by Parent Category or Category please
c
(@igneous)
Also looking for some code so I can sort by category
I’m putting some cash together to have it done for me so when I do , I’ll share the results, with you guys
c
(@igneous)
Awesome KTerceira, good luck π