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

According to: http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters Default order is DESC and default orderby is date. In a custom plugin, plugin is applying the following pre_get_posts filter: function custom_search_filter($query) { //echo ‘<pre>’; var_dump($_GET); echo ‘</pre>’; die; //echo ‘<pre>’; var_dump($query); echo ‘</pre>’; die; if ($query->is_search) { /* ————————————————– */ $query->set(‘orderby’, ‘date’); if ( isset($_GET[‘order’]) ) { if ( $_GET[‘order’] == … Read more

WP_Query orderby breaks when using AJAX?

I’m running in to a bit of a problem. I have a function called get_press(), it retrieves newest press items. It is inside of a plugin: class EWPress { function __construct() { load_plugin_textdomain( ‘ew’, flase, dirname( plugin_basename( __FILE__ ) ) . ‘/lang’ ); add_action( ‘wp_enqueue_scripts’, array( &$this, ‘register_plugin_scripts’ ) ); // Add JS var ajaxurl … Read more

Order posts by category name

Is there any way to order posts by category name? I tried $args = array( ‘post_type’ => ‘dlm_download’, ‘posts_per_page’ => 10, ‘paged’ => $paged, ‘order_by’=> ‘cat’, ‘order’ => ‘ASC’ ); But it does not really work, could please someone give me a hint? 2 Answers 2 I had the same struggle like you, thank i … Read more

How to use order RAND() on WordPress?

Attention: It’s order, not orderby. According to wordpress docs, there are only two options to order, which are ASC or DESC. The problem is: I would like to randomize the posts I’ve selected, not randomize WHICH posts I select. Here’s my code for better explanation: <?php return array( “post_type” => “listings”, “post_status” => “publish”, ‘meta_query’=>array( … Read more

WordPress Ordering Problem. How to fix ordering 1-10-100 issue?

I have categories the names of which are 1 to 25. But the WordPress ordering system doesn’t work correctly. It orders them as 1,10,11,12,13…2,21,22,23,24,25. I don’t want to add 0 to 1-9 numbers. How can I fix this issue? This is my code: <li class=”categoriesx <?php echo print_category_slug( get_the_category( $post->ID) ); ?>” data-category=”<?php echo print_category_slug( … Read more

Orderby = none not working [duplicate]

This question already has answers here: WP_query ‘orderby=none’ Problem (4 answers) Closed 8 years ago. I’m trying to set ‘orderby = none’ to my loop but it is not working. Here’s my code: $query = new WP_Query(array(‘showposts’=>2, ‘post__in’ => array(99,4,5,2,8,55), ‘orderby’=>’none’)); Could anyone help me? Thanks. 2 Answers 2 Order by none doesn’t do what … Read more

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

The scenario a custom post type wiki a (hierarchical) custom taxonomy topics a page template archive-wiki.php The situation Posts show up and get ordered by post_date (which is the default). The according core query is: SELECT SQL_CALC_FOUND_ROWS {$wpdb->prefix}posts.ID FROM {$wpdb->prefix}posts WHERE 1=1 AND {$wpdb->prefix}posts.post_type=”wiki” AND ({$wpdb->prefix}posts.post_status=”publish” OR {$wpdb->prefix}posts.post_status=”private”) ORDER BY {$wpdb->prefix}posts.post_date DESC LIMIT 0, {$setting->posts_per_page} … Read more

WP_Query order by date in meta_value

i have a small problem i think. this is my code for my category-releases.php: <?php $paged = ( get_query_var(‘paged’) ) ? get_query_var(‘paged’) : 1; $args = array( ‘posts_per_page’ => ’16’, ‘paged’ => $paged, ‘meta_key’ => ‘releaseDate’); $posts = get_posts($args); ?> <?php $wp_query = new WP_Query( $args ) ?> <?php while ( have_posts() ) : the_post(); … Read more