0

i have a query post :

$args3 = array(
    'posts_per_page'=>20,
    'post_type'=>array('num1','num2'),
    's' => urldecode($command),
    'orderby'   => 'type',
    'order' => 'ASC'
    );
query_posts($args3);

i want in result first show num1 post type results before num2 . what should i do ?

1
  • if i use 2 query i must use a lot of codes for limit number of posts but with 1 query i know how many post will show in result. in wordpress codex : codex.wordpress.org/Class_Reference/… there is a line for order by post type but there is no example...
    – Sajjad Sky
    Aug 11, 2017 at 10:58

1 Answer 1

0

Here is solution for your prob dude

add_filter( 'posts_request' , 'modify_request' );
function modify_request( $query) {
    global $wpdb;
    if(strstr($query,"post_type IN ('review', 'directory')")){
        $where = str_replace("ORDER BY {$wpdb->posts}.post_date","ORDER BY {$wpdb->posts}.post_type",$query);
    }
    return $where;
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.