Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Put these filters in functions.php or leave them here and put all of this in your template
- function mam_posts_fields ($fields) {
- global $mam_global_fields;
- // Make sure there is a leading comma
- 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');
- // Sample showing how to set the filters and display the results
- $mam_global_fields = ", IF($wpdb->posts.post_title REGEXP('^the '),CONCAT(SUBSTR($wpdb->posts.post_title,5), ', ', SUBSTR($wpdb->posts.post_title,1,4)),$wpdb->posts.post_title) AS sort_title";
- $mam_global_orderby = " UPPER(sort_title) ASC";
- query_posts("posts_per_page=-1");
- $mam_global_fields = $mam_global_orderby = ''; // Turn off filters
- if (have_posts()) {
- while (have_posts()) {
- the_post();
- echo "$post->sort_title<br />";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement