WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] custom post not showing content of post in columns (5 posts)

  1. strik3r2
    Member
    Posted 4 years ago #

    Not sure if i have explained my problem sufficiently in the title but i am creating a 4 custom post type and defining them in my functions.php file. I have created 3 custom post types without a problem however on the forth one it will not display the content in the columns i have defined.

    these are my functions

    //add a filter and an action to the events custom post type
     add_filter('manage_edit-events_columns', 'events_edit_columns');
     add_action('manage_posts_custom_column', 'events_custom_columns');
    
    //edit events columns names
    	function events_edit_columns ($columns) {
    		$columns = array(
    				"cb" => "<input type=\"checkbox\" />",
    				"title" => "Event Name",
    				"type" => "Event Type",
    				"location" => "Location",
    				"dates" => "Date",
    				"time" => "time",
    				"image" => "Image"
    			);
    
    		return $columns;
    	}
    
    	//edit content for all the added columns
    	//for the events custom post type
    	function events_custom_columns ($column) {
    		global $post;
    
    		switch($column)
    		{
    			case "type":
    				$custom = get_post_custom();
    				echo $custom["events_type"][0];
    				break;
    			case "location":
    				$custom = get_post_custom();
    				echo $custom["events_location"][0];
    				break;
    			case "dates":
    				$custom = get_post_custom();
    				echo $custom['events_date'][0];
    				break;
    			case "time":
    				$custom = get_post_custom();
    				echo $custom['events_time'][0];
    				break;
    			case "image":
    				$custom = get_post_custom();
    				echo $custom['events_image'][0];
    				break;
    		}
    	}
  2. Mark / t31os
    Moderator
    Posted 4 years ago #

    If this is a hierarchal post type(like pages) try changing this.

    add_action('manage_posts_custom_column', 'events_custom_columns');

    ..to..

    add_action('manage_pages_custom_column', 'events_custom_columns');

    ..and see if that helps.

  3. strik3r2
    Member
    Posted 4 years ago #

    ahh.. thanks so much.. worked like a charm.

  4. Mark / t31os
    Moderator
    Posted 4 years ago #

    Read about a similar problem recently, sprung into my mind when i read your post.

    Happy i could help.. ;)

  5. Derek
    Member
    Posted 3 years ago #

    Thank you so much! I have been searching for days on why my categories weren't showing up.

    Works great now!

Topic Closed

This topic has been closed to new replies.

About this Topic