Skip to main content
deleted 40 characters in body
Source Link
honk31
  • 1.4k
  • 1
  • 13
  • 23

I found the key: SQL CASE Expression

add_filter( 'posts_orderby', 'order_search_by_posttype', 10, 2 );
function order_search_by_posttype( $orderby, $wp_query ){
    if( (! $wp_query->is_adminis_admin() && $wp_query->is_search is_search()) :
        global $wpdb;
        $orderby =
            "
            CASE WHEN {$wpdb->prefix}posts.post_type = 'artist' THEN '1' 
                 WHEN {$wpdb->prefix}posts.post_type = 'post' THEN '2' 
                 WHEN {$wpdb->prefix}posts.post_type = 'artwork' THEN '3' 
                 WHEN {$wpdb->prefix}posts.post_type = 'publication' THEN '4' 
            ELSE {$wpdb->prefix}posts.post_type END ASC, 
            {$wpdb->prefix}posts.post_title ASC";
    endif;
    return $orderby;
}
add_filter('posts_orderby', 'order_search_by_posttype');

I found the key: SQL CASE Expression

add_filter( 'posts_orderby', 'order_search_by_posttype', 10, 2 );
function order_search_by_posttype( $orderby, $wp_query ){
    if( ! $wp_query->is_admin && $wp_query->is_search ) :
        global $wpdb;
        $orderby =
            "
            CASE WHEN {$wpdb->prefix}posts.post_type = 'artist' THEN '1' 
                 WHEN {$wpdb->prefix}posts.post_type = 'post' THEN '2' 
                 WHEN {$wpdb->prefix}posts.post_type = 'artwork' THEN '3' 
                 WHEN {$wpdb->prefix}posts.post_type = 'publication' THEN '4' 
            ELSE {$wpdb->prefix}posts.post_type END ASC, 
            {$wpdb->prefix}posts.post_title ASC";
    endif;
    return $orderby;
}

I found the key: SQL CASE Expression

function order_search_by_posttype($orderby){
    if (!is_admin() && is_search()) :
        global $wpdb;
        $orderby =
            "
            CASE WHEN {$wpdb->prefix}posts.post_type = 'artist' THEN '1' 
                 WHEN {$wpdb->prefix}posts.post_type = 'post' THEN '2' 
                 WHEN {$wpdb->prefix}posts.post_type = 'artwork' THEN '3' 
                 WHEN {$wpdb->prefix}posts.post_type = 'publication' THEN '4' 
            ELSE {$wpdb->prefix}posts.post_type END ASC, 
            {$wpdb->prefix}posts.post_title ASC";
    endif;
    return $orderby;
}
add_filter('posts_orderby', 'order_search_by_posttype');
was throwing an error since is_search() was not yet set.
Source Link
honk31
  • 1.4k
  • 1
  • 13
  • 23

I found the key: SQL CASE Expression

add_filter( 'posts_orderby', 'order_search_by_posttype', 10, 12 );
function order_search_by_posttype( $orderby, $wp_query ){
    if( ! is_admin()$wp_query->is_admin && is_search()$wp_query->is_search ) :
        global $wpdb;
        $orderby =
            "
            CASE WHEN {$wpdb->prefix}posts.post_type = 'artist' THEN '1' 
                 WHEN {$wpdb->prefix}posts.post_type = 'post' THEN '2' 
                 WHEN {$wpdb->prefix}posts.post_type = 'artwork' THEN '3' 
                 WHEN {$wpdb->prefix}posts.post_type = 'publication' THEN '4' 
            ELSE {$wpdb->prefix}posts.post_type END ASC, 
            {$wpdb->prefix}posts.post_title ASC";
    endif;
    return $orderby;
}

I found the key: SQL CASE Expression

add_filter( 'posts_orderby', 'order_search_by_posttype', 10, 1 );
function order_search_by_posttype( $orderby ){
    if( ! is_admin() && is_search() ) :
        global $wpdb;
        $orderby =
            "
            CASE WHEN {$wpdb->prefix}posts.post_type = 'artist' THEN '1' 
                 WHEN {$wpdb->prefix}posts.post_type = 'post' THEN '2' 
                 WHEN {$wpdb->prefix}posts.post_type = 'artwork' THEN '3' 
                 WHEN {$wpdb->prefix}posts.post_type = 'publication' THEN '4' 
            ELSE {$wpdb->prefix}posts.post_type END ASC, 
            {$wpdb->prefix}posts.post_title ASC";
    endif;
    return $orderby;
}

I found the key: SQL CASE Expression

add_filter( 'posts_orderby', 'order_search_by_posttype', 10, 2 );
function order_search_by_posttype( $orderby, $wp_query ){
    if( ! $wp_query->is_admin && $wp_query->is_search ) :
        global $wpdb;
        $orderby =
            "
            CASE WHEN {$wpdb->prefix}posts.post_type = 'artist' THEN '1' 
                 WHEN {$wpdb->prefix}posts.post_type = 'post' THEN '2' 
                 WHEN {$wpdb->prefix}posts.post_type = 'artwork' THEN '3' 
                 WHEN {$wpdb->prefix}posts.post_type = 'publication' THEN '4' 
            ELSE {$wpdb->prefix}posts.post_type END ASC, 
            {$wpdb->prefix}posts.post_title ASC";
    endif;
    return $orderby;
}
the 2, that i changed to one, indicated the arguments, that the function order_search_by_posttype accepts. its just 1, so this is the correct value
Source Link
honk31
  • 1.4k
  • 1
  • 13
  • 23

I found the key: SQL CASE Expression

add_filter( 'posts_orderby', 'order_search_by_posttype', 10, 21 );
function order_search_by_posttype( $orderby ){
    global $wpdb;
    if( ! is_admin() && is_search() ) :
        global $wpdb;
        $orderby =
        "CASE    "
            CASE WHEN {$wpdb->prefix}posts.post_type = 'artist' THEN '1' 
                 WHEN {$wpdb->prefix}posts.post_type = 'post' THEN '2' 
                 WHEN {$wpdb->prefix}posts.post_type = 'artwork' THEN '3' 
                 WHEN {$wpdb->prefix}posts.post_type = 'publication' THEN '4' 
              ELSE {$wpdb->prefix}posts.post_type END ASC, 
            {$wpdb->prefix}posts.post_title ASC";
    endif;
    return $orderby;
}

I found the key: SQL CASE Expression

add_filter( 'posts_orderby', 'order_search_by_posttype', 10, 2 );
function order_search_by_posttype( $orderby ){
    global $wpdb;
    if( ! is_admin() && is_search() ) :
    $orderby =
        "CASE WHEN {$wpdb->prefix}posts.post_type = 'artist' THEN '1' 
              WHEN {$wpdb->prefix}posts.post_type = 'post' THEN '2' 
              WHEN {$wpdb->prefix}posts.post_type = 'artwork' THEN '3' 
              WHEN {$wpdb->prefix}posts.post_type = 'publication' THEN '4' 
              ELSE {$wpdb->prefix}posts.post_type END ASC, 
        {$wpdb->prefix}posts.post_title ASC";
    endif;
    return $orderby;
}

I found the key: SQL CASE Expression

add_filter( 'posts_orderby', 'order_search_by_posttype', 10, 1 );
function order_search_by_posttype( $orderby ){
    if( ! is_admin() && is_search() ) :
        global $wpdb;
        $orderby =
            "
            CASE WHEN {$wpdb->prefix}posts.post_type = 'artist' THEN '1' 
                 WHEN {$wpdb->prefix}posts.post_type = 'post' THEN '2' 
                 WHEN {$wpdb->prefix}posts.post_type = 'artwork' THEN '3' 
                 WHEN {$wpdb->prefix}posts.post_type = 'publication' THEN '4' 
            ELSE {$wpdb->prefix}posts.post_type END ASC, 
            {$wpdb->prefix}posts.post_title ASC";
    endif;
    return $orderby;
}
added 15 characters in body
Source Link
honk31
  • 1.4k
  • 1
  • 13
  • 23
Loading
Source Link
honk31
  • 1.4k
  • 1
  • 13
  • 23
Loading