0

I have some trouble.

/* Catalog */
function my_post_type_catalog() {
    register_post_type( 'catalog',
                array( 
                'label' => __('Catalog'), 
                'public' => true, 
                'show_ui' => true,
                'show_in_nav_menus' => true,
                'rewrite' => true,
                'hierarchical' => true,
                'menu_position' => 5,
                'supports' => array(
                        'title',
                        'editor',
                        'thumbnail',
                        'excerpt')
                    ) 
                );
    register_taxonomy('catalog_cat', 'catalog', array('hierarchical' => true, 'label' => 'Catalog category', 'singular_name' => 'catalog_category'));
}

add_action('init', 'my_post_type_catalog');


add_action("admin_init", "admin_init");

function admin_init(){
    add_meta_box("catalogdetails_meta", "Price:", "catalog_meta",  "catalog", "normal", "low");
}

function catalog_meta() {
  global $post;
  $custom = get_post_custom($post->ID);
  $price = $custom["price"][0];
  ?>  

    <div id='peoplemanager_form_container'>

        <div id='shortanswers'>
            <p><input name="price" size="35" value="<?php echo $price; ?>"></p>
        </div>
    </div>
  <?php
}

add_action('save_post', 'save_details');

function save_details(){
  global $post;

  update_post_meta($post->ID, "price", $_POST["price"]);
}


// Register the column
function price_column_register( $columns ) {
    $columns['price'] = __( 'Price' );

    return $columns;
}
add_filter( 'manage_edit-catalog_columns', 'price_column_register' );


// Display the column content
function price_column_display( $column_name, $post_id ) {
    if ( 'price' != $column_name )
        return;

    $price = get_post_meta($post_id, 'price', true);
    if ( !$price )
        $price = '<em>' . __( 'undefined' ) . '</em>';

    echo $price;
}
add_action( 'manage_catalog_post_custom_column', 'price_column_display', 10, 2 );


// Register the column as sortable
function price_column_register_sortable( $columns ) {
    $columns['price'] = 'price';

    return $columns;
}
add_filter( 'manage_edit-catalog_sortable_columns', 'price_column_register_sortable' );


function price_column_orderby( $vars ) {
    if ( isset( $vars['orderby'] ) && 'price' == $vars['orderby'] ) {
        $vars = array_merge( $vars, array(
            'meta_key' => 'price',
            'orderby' => 'meta_value_num'
        ) );
    }

    return $vars;
}
add_filter( 'request', 'price_column_orderby' );

The price values not shows. What do I wrong ?
... Thanks for @Brady

need replace this code:

// Display the column content
function price_column_display( $column_name, $post_id ) {
    if ( 'price' != $column_name )
        return;

    $price = get_post_meta($post_id, 'price', true);
    if ( !$price )
        $price = '<em>' . __( 'undefined' ) . '</em>';

    echo $price;
}
add_action( 'manage_catalog_post_custom_column', 'price_column_display', 10, 2 );

to:

// Display the column content
add_action('manage_catalog_posts_custom_column', 'sc_stores_manage_columns', 10, 2);
function sc_stores_manage_columns($column_name, $id) {
    $custom = get_post_custom($id);
    switch ($column_name) {
        case 'price':
            if ($custom["price"][0]==""){echo "none";}
            echo $custom["price"][0];
        break;
    }
}

1 Answer 1

0

add_action( 'manage_post_custom_column', 'price_column_display', 10, 2 );

This line is wrong. I think it should be:

add_action( 'manage_catalog_post_custom_column', 'price_column_display', 10, 2 );

The hook format is as follows:

manage_{$post_type}_posts_custom_column

EDIT:

try your custom column code like the following code. I know in this format it works:

add_action('manage_stores_posts_custom_column', 'sc_stores_manage_columns', 10, 2);
function sc_stores_manage_columns($column_name, $id) {
    $custom = get_post_custom($id);
    switch ($column_name) {
        case 'town':
            echo $custom["sc_stores_town"][0];
        break;

        case 'road':
            echo $custom["sc_stores_road"][0];
        break;
    }
}
4
  • its not working
    – Alexey
    Commented Jun 24, 2011 at 5:41
  • please update your question to include the updated code. And nots not working? please me a bit more specific
    – Scott
    Commented Jun 24, 2011 at 6:14
  • sorting is works. but values not shows in column. dropmocks.com/mWtcb
    – Alexey
    Commented Jun 24, 2011 at 7:35
  • @Bobrov Alexey see edit.
    – Scott
    Commented Jun 24, 2011 at 8:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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