How do I output the contents of an arbitrary field of posts to a Wordpress column?

21 Views Asked by At

I know that such a question has been solved 100 times and I have tried these 100 solutions.

There is a self-written job plugin (I didn't write it). The plugin has structure - Job/Resume/Company. URL:

  • ../edit.php?post_type=job
  • ~../edit.php?post_type=resume
  • ../edit.php?post_type=company

In the Companies section, I need to display additional columns of INN, Phone number. I have displayed the columns on the page, I will attach the code. enter image description here

But I can't pass values to these columns..

enter image description here

Here is my code for adding columns and values for them,adding to function.php plugin:

<?php
....
/*--Создаем столбцы--*/
function set_custom_edit_company_columns($columns) {
unset( $columns\['Company'\] );
$columns\['company_inn'\] = \_\_( 'INN', 'your_text_domain' );
$columns\['company_phone'\] = \_\_( 'Phone', 'your_text_domain' );

    return $columns;

}
add_filter( 'manage_edit-company_columns', 'set_custom_edit_company_columns' );

/*--Передаем информацию в эти столбцы--*/

function custom_company_column( $column, $post_id ) {
switch ( $column ) {

        case 'company_inn' :
            $terms = get_the_term_list( $post_id , 'company_inn' , '' , ',' , '' );
            if ( is_string( $terms ) )
                echo $terms;
            else
                _e( 'ИНН не найден', 'your_text_domain' );
            break;
    
        case 'company_phone' :
            echo get_post_meta( $post_id , 'company_phone' , true ); 
            break;
    
    }

}
add_action( 'manage_company_posts_custom_column' , 'custom_company_column', 10, 2 );
....
?>

That's how the plugin works:

enter image description here

These fields are passed when creating a vacancy in the plugin:

<?php
....
public function initFields()
{
$this-\>fields = \[
'post_title' =\> $\_POST\['title'\] ?? '',
'post_content' =\> $\_POST\['description'\] ?? '',
'employer_category' =\> $\_POST\['employer_category'\] ?? '1',
'company_email' =\> $\_POST\['company_email'\] ?? '',
'company_phone' =\> $\_POST\['company_phone'\] ?? '',
'company_inn' =\> $\_POST\['company_inn'\] ?? '',
'company_url' =\> $\_POST\['company_url'\] ?? '',
'company_address' =\> $\_POST\['company_address'\] ?? '',

        ];
    
    }
....
?>

Please help ..

Described everything above

0

There are 0 best solutions below