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 ?

  • 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 '17 at 10:58
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, privacy policy and cookie policy

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