Title: [Plugin: WP Favorite Posts] Sort favorite post
Last modified: August 20, 2016

---

# [Plugin: WP Favorite Posts] Sort favorite post

 *  Resolved [Colir](https://wordpress.org/support/users/colir/)
 * (@colir)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/plugin-wp-favorite-posts-sort-favorite-post/)
 * Hi,
    i would like to know if there a way to sort the favorite post listing by
   date, or by alphabetic order.
 * I display the favorite post in a custom template page and i try to add this query
   `?
   orderby=title&sort=0`
 * but without effect…the post are always displayed by the order they’ve been add
   to favorite..
 * thanks
 * [http://wordpress.org/extend/plugins/wp-favorite-posts/](http://wordpress.org/extend/plugins/wp-favorite-posts/)

Viewing 12 replies - 1 through 12 (of 12 total)

 *  [pilote](https://wordpress.org/support/users/pilote/)
 * (@pilote)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/plugin-wp-favorite-posts-sort-favorite-post/#post-2412016)
 * for a sort by date you can sort by IDs
    [sort()](http://www.php.net/manual/en/function.sort.php)_
   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](https://wordpress.org/support/users/colir/)
 * (@colir)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/plugin-wp-favorite-posts-sort-favorite-post/#post-2412054)
 * 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](https://wordpress.org/support/users/colir/)
 * (@colir)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/plugin-wp-favorite-posts-sort-favorite-post/#post-2412059)
 * 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;
       			}
       		}
       ```
   
 *  [pilote](https://wordpress.org/support/users/pilote/)
 * (@pilote)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/plugin-wp-favorite-posts-sort-favorite-post/#post-2412061)
 * // 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()](http://www.php.net/manual/en/function.natcasesort.php)]
   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
 *  [pilote](https://wordpress.org/support/users/pilote/)
 * (@pilote)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/plugin-wp-favorite-posts-sort-favorite-post/#post-2412062)
 * natcasesort() vs ksort() ?? need some test 🙂
 *  Plugin Author [Huseyin Berberoglu](https://wordpress.org/support/users/hberberoglu/)
 * (@hberberoglu)
 * [14 years, 5 months ago](https://wordpress.org/support/topic/plugin-wp-favorite-posts-sort-favorite-post/#post-2412108)
 * Thanks @pliote 🙂
 *  [tgiokdi](https://wordpress.org/support/users/tgiokdi/)
 * (@tgiokdi)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/plugin-wp-favorite-posts-sort-favorite-post/#post-2412197)
 * I’m a little lost as to where to put this bit of code, and how to call it up.
 *  [ZakS](https://wordpress.org/support/users/ziz0123/)
 * (@ziz0123)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/plugin-wp-favorite-posts-sort-favorite-post/#post-2412212)
 * Im also a little lost as to where to put the code, am keen to sort them!
 *  [KTerceira](https://wordpress.org/support/users/kterceira/)
 * (@kterceira)
 * [14 years, 1 month ago](https://wordpress.org/support/topic/plugin-wp-favorite-posts-sort-favorite-post/#post-2412214)
 * Can anyone advise how to sort by Parent Category or Category please
 *  [c](https://wordpress.org/support/users/igneous/)
 * (@igneous)
 * [14 years ago](https://wordpress.org/support/topic/plugin-wp-favorite-posts-sort-favorite-post/#post-2412216)
 * Also looking for some code so I can sort by category
 *  [KTerceira](https://wordpress.org/support/users/kterceira/)
 * (@kterceira)
 * [14 years ago](https://wordpress.org/support/topic/plugin-wp-favorite-posts-sort-favorite-post/#post-2412217)
 * 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](https://wordpress.org/support/users/igneous/)
 * (@igneous)
 * [14 years ago](https://wordpress.org/support/topic/plugin-wp-favorite-posts-sort-favorite-post/#post-2412218)
 * Awesome KTerceira, good luck 🙂

Viewing 12 replies - 1 through 12 (of 12 total)

The topic ‘[Plugin: WP Favorite Posts] Sort favorite post’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/wp-favorite-posts.svg)
 * [WP Favorite Posts](https://wordpress.org/plugins/wp-favorite-posts/)
 * [Support Threads](https://wordpress.org/support/plugin/wp-favorite-posts/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-favorite-posts/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-favorite-posts/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-favorite-posts/reviews/)

 * 12 replies
 * 7 participants
 * Last reply from: [c](https://wordpress.org/support/users/igneous/)
 * Last activity: [14 years ago](https://wordpress.org/support/topic/plugin-wp-favorite-posts-sort-favorite-post/#post-2412218)
 * Status: resolved