Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. function wpcf_create_temp_column($fields) {
  2. global $wpdb;
  3. $matches = 'The';
  4. $has_the = " CASE
  5. WHEN $wpdb->posts.post_title regexp( '^($matches)[[:space:]]' )
  6. THEN trim(substr($wpdb->posts.post_title from 4))
  7. ELSE $wpdb->posts.post_title
  8. END AS title2";
  9. if ($has_the) {
  10. $fields .= ( preg_match( '/^(s+)?,/', $has_the ) ) ? $has_the : ", $has_the";
  11. }
  12. return $fields;
  13. }
  14.  
  15. function wpcf_sort_by_temp_column ($orderby) {
  16. $custom_orderby = " UPPER(title2) ASC";
  17. if ($custom_orderby) {
  18. $orderby = $custom_orderby;
  19. }
  20. return $orderby;
  21. }
  22.  
  23. <?php
  24. $args_post = array('post_type' => 'release', 'orderby' => 'title', 'order' => 'ASC', 'posts_per_page' => -1, );
  25.  
  26. add_filter('post_fields', 'wpcf_create_temp_column'); /* remove initial 'The' from post titles */
  27. add_filter('posts_orderby', 'wpcf_sort_by_temp_column');
  28.  
  29. $loop = new WP_Query($args_post);
  30.  
  31. remove_filter('post_fields', 'wpcf_create_temp_column');
  32. remove_filter('posts_orderby', 'wpcf_sort_by_temp_column');
  33.  
  34. while ($loop->have_posts() ) : $loop->the_post();
  35. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement