How to order posts by alphabet with numbers at the end

With some help of this answer and this post I managed to get your desired sorting hooking into the posts_orderby filter. You would need to add some additional check so this only affects your post type and on your page of choice but this snippet gives you the required statement to get the Apple store … Read more

How to order posts (woocommerce products) alphabetically but ignore certain words, eg ‘The’ and ‘An’

Ok, worked it out via a little workaround. Add a new sorting function in Woocommerce, something like: https://gist.githubusercontent.com/bekarice/0df2b2d54d6ac8076f84/raw/wc-sort-by-postmeta.php works nicely, but remove the bit about meta values and keys since we’re not sorting by custom fields (though that could be a good workaround too). Change the orderby to be ‘name’. Eg post slug rather than … Read more

Orderby Post Views

You can sort your query by view number, using the meta key : $query = new WP_Query( array( ‘meta_key’ => ‘post_views_count’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘DESC’, ) ); This will query your posts based on the views. You can change DESC to ASC or RAND to achieve what you asked. To make it work … Read more

How Do I Order Posts by Modified Date? [duplicate]

Try this: function my_custom_ordering( $query ) { if($query->is_main_query() AND !is_admin() ) { if ( $query->is_home() || $query->is_category() || $query->is_tag() ){ $query->set( ‘orderby’, ‘modified’ ); } } } add_action( ‘pre_get_posts’, ‘my_custom_ordering’ ); This will set orderby field to modified in the WordPress query.

How to order posts by meta value?

As mentioned above, never use query_posts, as it breaks a lot of stuff. Use a filter like pre_get_posts instead. The filter pre_get_posts allows you to edit the query before it gets executedby WP. The following code will order by the meta value you want. I made it so it only works on the main query … Read more

Sorting Attributes order when using get_the_terms

You will need to sort them yourself: $terms = get_the_terms( $post->ID, ‘category’); foreach ( $terms as $term ) { $newterms[$term->slug] = $term; } ksort($newterms); foreach ( $newterms as $term ) { echo “<li>” .$term->name. “</li>”; } Or, if you feel adventurous, the same with a filter: function alpha_sort_terms($terms) { remove_filter(‘get_the_terms’,’alpha_sort_terms’); foreach ( $terms as $term … Read more

the_tags() : display the tags by the order they are typed in in the backend, not alphabetically

Follow the White Rabbit: the_tags() get_the_tag_list() get_the_term_list() get_the_terms() wp_get_object_terms() If you look through that last function, you should see this: $defaults = array(‘orderby’ => ‘name’, ‘order’ => ‘ASC’, ‘fields’ => ‘all’); You should have alphabetical order by default. And no, there are no filters I see that would allow you to directly alter the query, … Read more

How to alter query order direction using $query->set(‘order’, ‘ASC’); inside a pre_get_posts filter?

Yes, I got it: function custom_search_orderby($orderby) { global $wpdb; if ( is_search() ) { if ( isset($_GET[‘order’]) ) { if ( $_GET[‘order’] == ‘DESC’ ) { $orderby = $wpdb->prefix . “posts.post_date DESC”; } else { $orderby = $wpdb->prefix . “posts.post_date ASC”; } } } return $orderby; } add_filter(‘posts_orderby’, ‘custom_search_orderby’, 999);

Order by first name

Here is my solution function split_names( $name ) { $names = explode( ” “, trim( join( ” “, $name ) ) ); $first_name = array_shift( $names ); $last_name = array_pop( $names ); $middle_name = join( ” “, $names ); return array( “first_name” => $first_name, “middle_name” => $middle_name, “last_name” => $last_name ); } function sort_by_full_name( $arr1, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)