0

I'm a WPAlchemy enthusiast, this class really enhance my productivity, but there is some things I don't understand.

I started to create a custom post type for products, with description, price and available stock. Then I added some columns to this custom post type listing like the price and stock.

And then, I tried to make the stock column sortable, so I read the tutorial from Scribu but it seems to not work with the storage mode of WPAlchemy.

The ID of my metabox is "_sk", the name of my value is "stock", the name returned by the method get_the_name() is "_sk[stock]", and I use this code:

add_filter( 'manage_edit-products_sortable_columns', 'products_sortable_columns');
function products_sortable_columns( $columns ) {
    $columns['stock']   = 'stock';
    return $columns;
}

add_filter('request', 'stock_column_orderby');
function stock_column_orderby($vars) {
    if (isset($vars['orderby']) && 'stock' == $vars['orderby']) {
        $vars = array_merge( $vars, array(
          'meta_key' => '_sk[stock]',
          'orderby' => 'meta_value_num'
        ));
    }
    return $vars;
}    

But when I try to sort by stock, the list return me "No products".

Can you see the point? Is there trouble with the storage mode of WPAlchemy?

Thanks in advance for your help!

1 Answer 1

1

Your meta values are being stored as an array under a single field. You have to store them as individual fields to use them in queries.

See this explanation on WPAlchemy data storage modes.

1
  • How yeah thanks ! I saw this post from Dimas, and I changed the storage mode but didn't see anything in the databse because I didn't updated a product...
    – Volpeo
    Sep 12, 2011 at 15:47

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.