Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function wpcf_create_temp_column($fields) {
- global $wpdb;
- $matches = 'The';
- $has_the = " CASE
- WHEN $wpdb->posts.post_title regexp( '^($matches)[[:space:]]' )
- THEN trim(substr($wpdb->posts.post_title from 4))
- ELSE $wpdb->posts.post_title
- END AS title2";
- if ($has_the) {
- $fields .= ( preg_match( '/^(s+)?,/', $has_the ) ) ? $has_the : ", $has_the";
- }
- return $fields;
- }
- function wpcf_sort_by_temp_column ($orderby) {
- $custom_orderby = " UPPER(title2) ASC";
- if ($custom_orderby) {
- $orderby = $custom_orderby;
- }
- return $orderby;
- }
- <?php
- $args_post = array('post_type' => 'release', 'orderby' => 'title', 'order' => 'ASC', 'posts_per_page' => -1, );
- add_filter('post_fields', 'wpcf_create_temp_column'); /* remove initial 'The' from post titles */
- add_filter('posts_orderby', 'wpcf_sort_by_temp_column');
- $loop = new WP_Query($args_post);
- remove_filter('post_fields', 'wpcf_create_temp_column');
- remove_filter('posts_orderby', 'wpcf_sort_by_temp_column');
- while ($loop->have_posts() ) : $loop->the_post();
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement