Alphabetical order in taxonomy.php

The main query is generated before the template is loaded, the results of the main query are how WordPress knows what template to load. If you want to alter query parameters of the main query to change things like orderby, you should add a function hooked to pre_get_posts. The argument passed to the function contains … Read more

Customize the Sorting Dropdown in WooCommerce

Actually, with a little digging this is quite easy to do. WooCommerce has already set up a filter so all you have to do it add a small snippet in your functions.php file. // Modify the default WooCommerce orderby dropdown // // Options: menu_order, popularity, rating, date, price, price-desc function my_woocommerce_catalog_orderby( $orderby ) { unset($orderby[“price”]); … 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.

WooCommerce – Show orders for a specific product ? [closed]

Eric based on your code I wrote to meet my needs, for those who want to follow: Eric com base em seu código eu escrevi o para atender as minhas necessidades, para quem quiser segue abaixo: <?php global $wpdb; $produto_id = 22777; // ID do produto $consulta = “SELECT order_id FROM {$wpdb->prefix}woocommerce_order_itemmeta woim LEFT JOIN … Read more

Display custom post types by date field

I solved the same problem like this First you store each posts in another array called $events_by_date with date as the index. If another event post falls in the same date you put that post under the same index. Please comment if you need further explanation. <?php //setup your wp_query parmeters to make the query … Read more

Order post by year DESC and month ASC

To show a list by Year DESC and by month ASC: change your post type with custom_post. global $wpdb; $posts = $wpdb->posts; $sql = “SELECT DISTINCT(YEAR(`post_date`)) as years FROM $posts WHERE post_type=”custom_post” ORDER BY years DESC”; //Get all post year list by DESC $result = $wpdb->get_results($sql); foreach($result as $rs) { echo ‘<h2>’.$rs->years.'</h2>’; $args = array( … Read more

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

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