Support

Search results for ""

Sorry, no results found. Perhaps you would like to search the documentation?
All Topics
Pau Plana Salesas

Custom field colum render value

Hi,

With old version of ACPRO I was using the filter ac/column/value to render some values of custom field columns.
Now, after updated to the last version, this filter seems that doesn’t works fine and reading your hook documentationt I found the ac/column/render.

But in my case is not working.

In the AC view I have:

– column: custom field
– label: Nombre
– field: user_id

Because I’m trying to get a user value in a custom post type list.

In the old filter version I can access to get_custm_label() but now this doesn’t work…

I need help to understand how I need to change my function

Thanks in advance

1 week, 6 days ago
Tobias Schutter
Developer

Can you send me your old code that uses the ‘ac/column/value’ filter? I will have a look at it!

1 week, 6 days ago
Pau Plana Salesas

Yes, of course! Here you have:

/**
 * @param string    $value  The column value that is displayed within a cell on the list table
 * @param int       $id     Post ID, User ID, Comment ID, Attachement ID or Term ID
 * @param AC\Column $column Column object
 *
 * @return string
 */
function tip_acp_filter_columns( $value, $id, AC\Column $column ) {

	if ( $column instanceof AC\Column\CustomField ) {
		$user = get_user_by( 'id', (int) $value );

		if ( 'Especialidad' === $column->get_custom_label() ) {
			$prevalue = get_user_meta( $user->ID, 'service_unity', true );

			$su = [
				'cuidados-intensivos'   => 'Ciudados Intensivos',
				'medicina-de-urgencias' => 'Medicina de Urgencias',

				'neurocirugía'          => 'Neurocirugía',
				'neurocirugia'          => 'Neurocirugía',

				'neurología'            => 'Neurología',
				'neurologia'            => 'Neurología',

				'neuropsicología'       => 'Neuropsicología',
				'neuropsicologia'       => 'Neuropsicología',

				'anestesiología'        => 'Anestesiología',
				'anestesiologia'        => 'Anestesiología',

				'otros'                 => 'Otros',
			];

			$value = $su[ $prevalue ] ?? $prevalue;
		}
		if ( 'Categoría profesional' === $column->get_custom_label() ) {
			$prevalue = get_user_meta( $user->ID, 'professional_category', true );

			$pc = [
				'enfermeria'   => 'Diplomado Enfermería',
				'especialista' => 'Facultativo Especialista',
				'medico'       => 'Médico Residente',
				'otros'        => 'Otros',
			];

			$value = $pc[ $prevalue ] ?? $prevalue;
		}

		if ( 'Nombre' === $column->get_custom_label() ) {
			$value = $user->first_name;
		}
		if ( 'Apellido 1' === $column->get_custom_label() ) {
			$value = $user->last_name;
		}
		if ( 'Apellido 2' === $column->get_custom_label() ) {
			$value = get_user_meta( $user->ID, 'second_last_name', true );
		}
		if ( 'E-mail' === $column->get_custom_label() ) {
			$value = $user->user_email;
		}
		if ( 'Teléfono' === $column->get_custom_label() ) {
			$value = get_user_meta( $user->ID, 'billing_phone', true );
		}
		if ( 'DNI' === $column->get_custom_label() ) {
			$value = get_user_meta( $user->ID, 'billing_NIF', true );
		}
		if ( 'Ciudad' === $column->get_custom_label() ) {
			$value = get_user_meta( $user->ID, 'billing_city', true );
		}
		if ( 'País' === $column->get_custom_label() ) {
			$value = get_user_meta( $user->ID, 'billing_country', true );
		}
		if ( 'Hospital' === $column->get_custom_label() ) {
			$value = get_user_meta( $user->ID, 'company', true );
		}
	} else {
		if ( 'Especialidad' === $column->get_custom_label() ) {
			$su = [
				'cuidados-intensivos'   => 'Ciudados Intensivos',
				'medicina-de-urgencias' => 'Medicina de Urgencias',

				'neurocirugía'          => 'Neurocirugía',
				'neurocirugia'          => 'Neurocirugía',

				'neurología'            => 'Neurología',
				'neurologia'            => 'Neurología',

				'neuropsicología'       => 'Neuropsicología',
				'neuropsicologia'       => 'Neuropsicología',

				'anestesiología'        => 'Anestesiología',
				'anestesiologia'        => 'Anestesiología',

				'otros'                 => 'Otros',
			];

			$value = $su[ $value ];
		}

		if ( 'Categoría profesional' === $column->get_custom_label() ) {
			$pc = [
				'enfermeria'   => 'Diplomado Enfermería',
				'especialista' => 'Facultativo Especialista',
				'medico'       => 'Médico Residente',
				'otros'        => 'Otros',
			];

			$value = $pc[ $value ];
		}
	}

	return $value;

}
add_filter( 'ac/column/value', 'tip_acp_filter_columns', 10, 3 );
1 week, 6 days ago
Tobias Schutter
Developer

Here is an updated code snippet that works with ACP version 7 and later. I have also updated the hook documentation to include additional examples and details about the available properties when using our hooks and filters: https://docs.admincolumns.com/article/15-hooks-and-filters


function tip_acp_filter_columns($value, AC\Column\Context $column, $id, AC\TableScreen $table)
{
    if ($column instanceof AC\Column\CustomFieldContext) {
        $user = get_user_by('id', (int)$value);

        if ( ! $user) {
            return $value;
        }

        if ('Especialidad' === $column->get('label')) {
            $prevalue = get_user_meta($user->ID, 'service_unity', true);

            $su = [
                'cuidados-intensivos'   => 'Ciudados Intensivos',
                'medicina-de-urgencias' => 'Medicina de Urgencias',

                'neurocirugía' => 'Neurocirugía',
                'neurocirugia' => 'Neurocirugía',

                'neurología' => 'Neurología',
                'neurologia' => 'Neurología',

                'neuropsicología' => 'Neuropsicología',
                'neuropsicologia' => 'Neuropsicología',

                'anestesiología' => 'Anestesiología',
                'anestesiologia' => 'Anestesiología',

                'otros' => 'Otros',
            ];

            $value = $su[$prevalue] ?? $prevalue;
        }

        if ('Especialidad' === $column->get('label')) {
            $prevalue = get_user_meta($user->ID, 'service_unity', true);

            $su = [
                'cuidados-intensivos'   => 'Ciudados Intensivos',
                'medicina-de-urgencias' => 'Medicina de Urgencias',

                'neurocirugía' => 'Neurocirugía',
                'neurocirugia' => 'Neurocirugía',

                'neurología' => 'Neurología',
                'neurologia' => 'Neurología',

                'neuropsicología' => 'Neuropsicología',
                'neuropsicologia' => 'Neuropsicología',

                'anestesiología' => 'Anestesiología',
                'anestesiologia' => 'Anestesiología',

                'otros' => 'Otros',
            ];

            $value = $su[$prevalue] ?? $prevalue;
        }
        if ('Categoría profesional' === $column->get('label')) {
            $prevalue = get_user_meta($user->ID, 'professional_category', true);

            $pc = [
                'enfermeria'   => 'Diplomado Enfermería',
                'especialista' => 'Facultativo Especialista',
                'medico'       => 'Médico Residente',
                'otros'        => 'Otros',
            ];

            $value = $pc[$prevalue] ?? $prevalue;
        }

        if ('Nombre' === $column->get('label')) {
            $value = $user->first_name;
        }
        if ('Apellido 1' === $column->get('label')) {
            $value = $user->last_name;
        }
        if ('Apellido 2' === $column->get('label')) {
            $value = get_user_meta($user->ID, 'second_last_name', true);
        }
        if ('E-mail' === $column->get('label')) {
            $value = $user->user_email;
        }
        if ('Teléfono' === $column->get('label')) {
            $value = get_user_meta($user->ID, 'billing_phone', true);
        }
        if ('DNI' === $column->get('label')) {
            $value = get_user_meta($user->ID, 'billing_NIF', true);
        }
        if ('Ciudad' === $column->get('label')) {
            $value = get_user_meta($user->ID, 'billing_city', true);
        }
        if ('País' === $column->get('label')) {
            $value = get_user_meta($user->ID, 'billing_country', true);
        }
        if ('Hospital' === $column->get('label')) {
            $value = get_user_meta($user->ID, 'company', true);
        }
    } else {
        if ('Especialidad' === $column->get('label')) {
            $su = [
                'cuidados-intensivos'   => 'Ciudados Intensivos',
                'medicina-de-urgencias' => 'Medicina de Urgencias',

                'neurocirugía' => 'Neurocirugía',
                'neurocirugia' => 'Neurocirugía',

                'neurología' => 'Neurología',
                'neurologia' => 'Neurología',

                'neuropsicología' => 'Neuropsicología',
                'neuropsicologia' => 'Neuropsicología',

                'anestesiología' => 'Anestesiología',
                'anestesiologia' => 'Anestesiología',

                'otros' => 'Otros',
            ];

            $value = $su[$value];
        }

        if ('Categoría profesional' === $column->get('label')) {
            $pc = [
                'enfermeria'   => 'Diplomado Enfermería',
                'especialista' => 'Facultativo Especialista',
                'medico'       => 'Médico Residente',
                'otros'        => 'Otros',
            ];

            $value = $pc[$value];
        }
    }

    return $value;
}

add_filter('ac/column/render', 'tip_acp_filter_columns', 10, 4);
1 week, 6 days ago
Pau Plana Salesas

Thanks! Is working perfectly!!

Best regards and thanks for your fast support!

1 week, 5 days ago

You must be logged in to reply to this topic.