Support

Account

Home Forums Backend Issues (wp-admin) get_post_object() doesn't work inside columns when custom filter applied

Helping

get_post_object() doesn't work inside columns when custom filter applied

  • Hi,

    I’m trying to get a fields value and label inside a row in a custom column. Everything works fine when no filters are applied, but when I apply the filter nothing is showing up and I don’t know why.

    Here is the code sample (a bit modified):

    add_filter('manage_cptName_posts_columns' , 'add_cptName_columns', 1);
    function add_cptName_columns($columns) {
    
    	unset( $columns['date'] );
    
    	return array_merge($columns,
    		[ 'colum_one' 	=> 'Column One' ],
    		[ 'column_two' 		=> 'Column Two'] ,
    		[ 'date' 		=> 'Datum unosa' ]
    		);
    }
    
    add_action('manage_cptName_posts_custom_column' , 'cptName_custom_columns', 10, 2 );
    function cptName_custom_columns( $column, $post_id ) {
    	
    	// global $post; // tried both $post_id and $post->ID
    	switch ( $column ):
    
    		case 'column_one': 
    			echo '<pre>' . print_r( get_field_object('field_one', $post_id) , true) . '</pre>';
    			break;
    
    		case 'column_two':
    			echo '<pre>' . print_r( get_field_object('field_two') , true) . '</pre>';
    			break;
    
    	endswitch;
    }
  • I see that I wrote get_post_object, instead of get_field_object. I was thinking of get_field_object.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘get_post_object() doesn't work inside columns when custom filter applied’ is closed to new replies.