How do I get post attachments in menu_order in WordPress?
How do I get post attachments in menu_order in WordPress?
How do I get post attachments in menu_order in WordPress?
Menu items suddenly are displayed all over the page [closed]
Getting too long for a comment, sooo in my super simple test overriding up-sells.php on a fresh WC install with a WP_Query, I can change the orderby and order parameters and the products display in the order of my array of product ids: $meta_query = WC()->query->get_meta_query(); $my_upsells = [171, 170, 172]; $args = array( ‘post_type’ … Read more
By default, posts and pages are sorted after the date. If you want sort pages by “order” field, which is visible on edit page, you have to set orderby parameter: add_action(‘pre_get_posts’, ‘change_order’); function change_order($query) { if ( is_front_page() || is_home() ) { $query->set( ‘orderby’, ‘menu_order’ ); $query->set( ‘order’, ‘ASC’ ); } return $query; } Put … Read more
How to order WP_Query by parent for hierarchical Custom Post Type?
I forgot to add !is_admin() check to my pre_get_posts function. Altered section of code below. add_action( ‘pre_get_posts’, ‘mpe_portfolio_sort_order’); function mpe_portfolio_sort_order($query){ if(is_archive() && ! is_admin() ): $query->set( ‘order’, ‘ASC’ ); $query->set( ‘orderby’, ‘menu_order’ ); endif; };
This should help: You can use multiple fields in orderby argument. Codex shows you how to do it (and you do it correctly): $query = new WP_Query( array( ‘post_type’ => ‘page’, ‘orderby’ => ‘menu_order date’, ‘order’ => ‘ASC’ ) ); And it should solve your problem. (It should, but if you want to sort DESC … Read more
This is not an exact answer, but I think there are enough elements to build the desired output. I sort the menu manipulating the global $menu, not really best practice, but for now it works. The result of this example is moving Links Manager, Comments and Media Library to the end of the first block. … Read more
Advanced ordering feature is now added in the new version of WordPress. I came to know this after release of WordPress 4.0. Check this announcement for more detail. Example: $q = new WP_Query( array( ‘orderby’ => array( ‘title’ => ‘DESC’, ‘menu_order’ => ‘ASC’ ) ) );
Karun’s answer made me look more into the posts_where filter to find a better solution to hook into the WP_Query. After a bit more google searching I found this page that did it in a better way. Using that method I finally got it to work like this: add_filter(‘posts_where’, function ($where, $query) { global $wpdb; … Read more