WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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!

share|improve this question
up vote 1 down vote accepted

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.

share|improve this answer
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 '11 at 15:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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