Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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;
    }
}
share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

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;
    }
}
share|improve this answer
    
its not working –  Bobrov Alexey Jun 24 '11 at 5:41
    
please update your question to include the updated code. And nots not working? please me a bit more specific –  Brady Jun 24 '11 at 6:14
    
sorting is works. but values not shows in column. dropmocks.com/mWtcb –  Bobrov Alexey Jun 24 '11 at 7:35
    
@Bobrov Alexey see edit. –  Brady Jun 24 '11 at 8:23
    
thanks! working –  Bobrov Alexey Jun 24 '11 at 9:09
add comment

Your Answer

 
discard

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.