• Resolved fahaadsheikh

    (@fahaadsheikh)


    Orders in the orders tab on the WP Dashboard are not searchable. I tried searching by the email of the user, user name and the order number. I’ve solved this on my own by adding the following code into functions.php incase anyone needs it.

    function idsearch( $wp ) {
        global $pagenow;
        if ( $wp->extra_query_vars['post_type'] == 'llms_order') {
            // If it's not the post listing return
            if( 'edit.php' != $pagenow )
                return;
    
            // If it's not a search return
            if( !isset( $wp->query_vars['s'] ) )
                return;
    
            // If it's a search but there's no prefix, return
            if( '#' != substr( $wp->query_vars['s'], 0, 1 ) )
                return;
    
            // Validate the numeric value
            $id = absint( substr( $wp->query_vars['s'], 1 ) );
            if( !$id )
                return; // Return if no ID, absint returns 0 for invalid values
    
            // If we reach here, all criteria is fulfilled, unset search and select by ID instead
            unset( $wp->query_vars['s'] );
            $wp->query_vars['p'] = $id;
        }
    }
    add_action( 'parse_request', 'idsearch' );
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘Order not searchable’ is closed to new replies.