Tag Info

Hot answers tagged

4

Found the answer from the WordPress docs. For what the query is ordered by, I use: global $wp_query; echo $wp_query->get('orderby'); For the order by which the posts are queried: global $wp_query; echo $wp_query->get('order');


3

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 ...


1

Sometimes the easiest solution to this kind of problem is to use a meta data field in which you store the relevant value by which you want to sort. For "the stackexchange" you store "stackexhange" but for "mark kaplun" you just store "mark kaplun". This should be very trivial code to write. Once you have the sort values in place all that is left to do is ...


1

Yes, there is. Paste this in your function.php add_action('pre_get_posts','wpse_175699_alphabetical_order'); function wpse_175699_alphabetical_order($query) { if (is_category()) { $query->set('orderby', 'title'); $query->set('order', 'ASC'); } }


1

You cannot do this with the default paginate_links() functions. Looking at the source code, there are no filters from which you can change the layout as you wish ALTERNATIVE SOLUTIONS Although you cannot do this by default, it doesn't mean that you cannot get your desired output. Here is a couple of options to explore OPTION 1 Write a wrapper function ...


1

You could use the 'posts_orderby' filter: function custom_loops($query) { if ( is_post_type_archive('my_post_type') ){ $query->set( 'posts_per_page', 40); $query->set( 'meta_key', 'custom_meta_sponsored'); $query->set( 'orderby', 'custom_meta_sponsored'); $query->set( 'order', 'DESC'); add_filter( ...


1

One way to do it is to store the order of the tags as post meta data, using the action set_object_terms which happens to pass the tags in the order they appear on edit, eg in your "functions.php": // Called in admin on updating terms - update our order meta. add_action( 'set_object_terms', function ( $object_id, $terms, $tt_ids, $taxonomy, $append, ...


1

Given that meta is cached inside page load it should be reasonably performant to do it like this (not tested): usort( $wp_query->posts, function ( $post_a, $post_b ) { $a = get_post_meta( $post_a->id, 'key', true ); $b = get_post_meta( $post_b->id, 'key', true ); if ( $a == $b ) { return 0; } return ( $a < $b ) ? - 1 ...



Only top voted, non community-wiki answers of a minimum length are eligible