Automatically set page order on create page

You could use ajax and the admin_footer-post-new.php hook. The sql would vary depending on whether you want the highest or most recently published order number. The following returns the highest published order number + 1: function wpse155926_set_menu_order() { $ret = array(); if ( check_ajax_referer( ‘wpse155926_set_menu_order_post’, ‘nonce’, false /*die*/ ) ) { global $wpdb; //last published … Read more

Order by custom field date with ASC order

With some more googling: <?php $today = date(“Y/m/j”); query_posts(array( ‘post_type’ => ‘custompost’, ‘posts_per_page’ => 4, ‘meta_key’ => ‘mydate’, ‘orderby’ => ‘meta_value’, ‘order’ => ‘ASC’, ‘meta_query’ => array( array( ‘key’ => ‘mydate’, ‘meta-value’ => $value, ‘value’ => $today, ‘compare’ => ‘>=’, ‘type’ => ‘CHAR’ ) ) )); if (have_posts()) : while (have_posts()) : the_post(); ?> <a … Read more

Order users by custom user meta

Here’s the solution. Comments included: <?php $results = get_users(‘role=director’); foreach ($results as $result) { // Get data about each user as an object $user = get_userdata($result->ID); // Create a flat array with only the fields we need $directors[$user->ID] = array( ‘dir_order’ => $user->exit_director_order, ‘dir_id’ => $user->ID, ‘dir_name’ => $user->first_name.’ ‘.$user->last_name ); } // Sort sort($directors); … 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);

Orderby = none not working [duplicate]

Order by none doesn’t do what you think it does. If you don’t specify an order, then MySQL doesn’t guarantee any particular order and will simply get the posts in whatever order it has them. Since they were inserted in a particular order, then you’ll probably get them in that order. Since you need the … Read more

Order posts by (hierarchical custom) taxonomy terms and term children

This query will handle two levels of hierarchy in your taxonomy. More than two levels of hierarchy and you’ll need a recursive self-join. What this does is return the posts in the correct child within parent order. To create the appropriate parent level headings, you’ll have compare the current post’s parent taxon with that of … Read more

Increment Page Order As Pages Are Created

The following is a possible solution, but needs some testing to confirm it is viable. It runs only if menu_order == 0 and if it’s not an auto-draft or revision being saved add_action( ‘save_post’, ‘incremental_save_wpse_113767’, 10, 2 ); function incremental_save_wpse_113767( $post_id, $post_object ) { if( defined( ‘DOING_AUTOSAVE’ ) && DOING_AUTOSAVE ) return; if( defined( ‘DOING_AJAX’ … Read more

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