• Resolved chachalady

    (@chachalady)


    Hello, I have a custom post type called “hks-najave” (“najave” means “future events”), very basic and simple post type for storing events:
    -title
    -description
    -event date ( I do not need start-end dates, just simple single date)
    -featured image
    (people can add category and tags – optionaly)

    I am still learning about custom post types and here I did well with registering my cpt hks-najave and with querying, displaying and sorting events (begining from most recent )on my custom page template.
    Even dates I managed to display the way/format I want.

    But I have a problem with cpt list in admin area. By default, in my admin area for custom post type hks-najave I can see the basic few columns: title, category, tag, and date when the post was published.

    I have a custom field “datum-najave” that stors event date.
    So far I managed to make/add a new column and even make the column sortable, but the code I add to my functions.php causes me problems:
    – when I want to add new custom post and publish it it leads me to blank screen.
    Post is added but something is going wrong after clicking “publish” since I get the blank screen.
    Same thing with normal, regular posts. Blank screen after hitting “publish” or “move to trash”.
    And when I want to add featured image – images in media library are not showing.

    When I remove the code from functions.php everything is ok again.

    This is the code:

    <?php
    
    // Register a new column in the admin Post area
    
    add_filter('manage_edit-hks-najave_columns', 'my_dat_najave_column');
    function my_dat_najave_column($columns) {
        $columns['datumnajave'] =__('Datum najave');
        return $columns;
    }  
    
    // add content
    
    add_action( 'manage_hks-najave_posts_custom_column', 'my_dat_najave_column_content', 10, 2 );
    function my_dat_najave_column_content( $column_name, $post_id ) {
        if ( 'datumnajave' != $column_name )
            return;
        //Get dates from post meta
        $datumnajave = get_post_meta($post_id, 'datum_najave', true);
        echo intval($datumnajave);
    }  
    
    //  make the column sortable
    
    add_filter( 'manage_edit-hks-najave_sortable_columns', 'my_sortable_datum_column' );
    function my_sortable_datum_column( $columns ) {
        $columns['datumnajave'] = 'datum';  
    
        //To make a column 'un-sortable' remove it from the array
        //unset($columns['date']);  
    
        return $columns;
    }  
    
    add_action( 'pre_get_posts', 'my_datum_orderby' );
    function my_datum_orderby( $query ) {
        if( ! is_admin() )
            return;  
    
        $orderby = $query->get( 'orderby');  
    
        if( 'datum' == $orderby ) {
            $query->set('meta_key','datum_najave');
            $query->set('orderby','meta_value_num');
        }
    }  ?>

    Maybe you can figure out why this code is causing me problems.
    Column is displaying, and it is sortable – only dates are not in pretty format but i will work on that.

    But I can not leve the code there since it causes problems during publishing.
    Site is running with wp 3.5.2, in a next few days I will update it,
    but I think the wordpress version is not the reason of the problem …

    Maybe there is a better way to add custom column to cpt, with dates.
    My cpt name is “hks-najave” , custom field with date is called: ” datum_najave “.
    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter chachalady

    (@chachalady)

    Update:

    I updated wordpress to new 3.6.1. version and I found a empty line in my functions.php between ?> and next <?php .

    So, blank screen could be because I did not see that empty line between

    Now blank page is no longer an issue.

    Thread Starter chachalady

    (@chachalady)

    Above code is working and I have a event-date column.

    The only thing is it doesnt sort it on default – when I open the admin area with custom post list first it sorts it by publish date.
    Then if I click on sortable column events are sorted.

    Another thing is that event date is not in a good looking format, it looks like: 20131026 , 20131017, 20130925 etc.

    I will post this as separate topic if I will not find a solution.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Custom column-event date,admin area- problems-publish button leads to blank scr’ is closed to new replies.