Sort list of posts (decending) by day of the week
-
Hi
I should sort a lsit of posts by a custom field “daynumber” repeating weekly.
I found this resolved post in this forum but get an error:
https://www.ads-software.com/support/topic/sort-list-of-posts-decending-by-day-of-the-week?replies=12Here is what i have so far, thats exactly like the last answer:
<?php function mam_posts_fields ($fields) { global $mam_global_fields; if ($mam_global_fields) $fields .= (preg_match('/^(\s+)?,/',$mam_global_fields)) ? $mam_global_fields : ", $mam_global_fields"; return $fields; } function mam_posts_orderby ($orderby) { global $mam_global_orderby; if ($mam_global_orderby) $orderby = $mam_global_orderby; return $orderby; } add_filter('posts_fields','mam_posts_fields'); add_filter('posts_orderby','mam_posts_orderby'); $today = date('w') + 1; // Day of week with 1 for Sunday $tomorrow = ($today == 7) ? 1 : $today + 1; $mam_global_fields = ", if(meta_value < $tomorrow, meta_value + 7, meta_value) as sortfield "; $mam_global_orderby = " sortfield ASC"; $args = array( 'post_type' => 'standort', 'meta_key' => 'daynumber', 'posts_per_page' => 5 ); query_posts($args); ?>
This works. Posts are sorted.
But I have 3 more query`s on the same page, and there is get the error.</strong>WordPress database error: [Unknown column 'meta_value' in 'field list'] SELECT SQL_CALC_FOUND_ROWS phillswp_posts.*, if (meta_value < 7, meta_value + 7, meta_value) as sortfield FROM phillswp_posts INNER JOIN phillswp_term_relationships ON (phillswp_posts.ID = phillswp_term_relationships.object_id) WHERE 1=1 AND ( phillswp_term_relationships.term_taxonomy_id IN (1) ) AND phillswp_posts.post_type = 'post' AND (phillswp_posts.post_status = 'publish' OR phillswp_posts.post_status = 'private') GROUP BY phillswp_posts.ID ORDER BY sortfield ASC LIMIT 0, 1
Does anyone have a hint where this error cames from?
Thank you
Roman
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘Sort list of posts (decending) by day of the week’ is closed to new replies.