Support

Search results for ""

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

field url

Hello,
Please I added a file field in acf on a cpt, I recorded the post with the file in question, when I try to display a column of type URL for this field, nothing happens, it goes blank, how can I solve this?

7 years, 4 months ago
Stefan van den Dungen Gronovius
Developer

Hi Marcelo,

This is what happening.
The ACF file field stores the value as an integer in the database.
So when you use a custom field column and select this ACF key, it will show you an ID as default.

The URL type can make a plain URL a clickable link, but the initial value must already be a URL.
Since your value is not an URL, the column will display no value at all.
You could try the field type ‘Post Title’ as it will give you the files title and a link to the edit page for that file (not the fileurl).

If you really want a link to the file, you have to use one of our filters to make the link yourself. You should be able to manage it with this filter: https://www.admincolumns.com/documentation/filter-reference/cac-column-meta-value/

7 years, 4 months ago
Marcelo

I understand, could you show me an example filter for this condition in php to work?

7 years, 4 months ago
Stefan van den Dungen Gronovius
Developer

You could do something like this.

function acp_make_link_from_acf_id_value( $value, $object_id, $column ) {
	$custom_field_key = 'acf_file'; // Change it to your ACF key

	if ( 'column-meta' == $column->get_type() && $custom_field_key == $column->get_field() ) {

		$value = $value ? wp_get_attachment_link( $value ) : '';

	}

	return $value;
}
add_filter( 'cac/column/meta/value', 'acp_make_link_from_acf_id_value', 10, 3 );
7 years, 4 months ago
Marcelo

Hi Stefan,
I inserted the reference code in function:

function acp_make_link_from_acf_id_value( $value, $object_id, $column ) {
	$custom_field_key = 'acf-field-5846c51924d70'; // Change it to your ACF key

	if ( 'column-meta' == $column->get_type() && $custom_field_key == $column->get_field() ) {

		$value = $value ? wp_get_attachment_link( $value ) : '';

	}

	return $value;
}
add_filter( 'cac/column/meta/value', 'acp_make_link_from_acf_id_value', 10, 3 );

I entered the $custom_field_key as ‘acf-field …’ I tried ‘field …’ only the numbers, but it did not work, I configured it in more than one custom post type to check if this was a problem, but it is not.

Do you think I’m doing something wrong?

Tks.

7 years, 3 months ago
Stefan van den Dungen Gronovius
Developer

Hi Marcelo,

I think the snippet is correct but maybe one of the checks is failing.
Try to debug it by alway output the key

echo $column->get_field()
or
$value = $column->get_field()

In that case you know for sure if the values is changed at all. And you’ll get the correct ACF key to work with.
Or only try just one if statement instead of two. If that doesn’t work, try to build the function from scratch

function acp_make_link_from_acf_id_value( $value, $object_id, $column ) {
	$value = 'value is changed';
	return $value;
}
add_filter( 'cac/column/meta/value', 'acp_make_link_from_acf_id_value', 10, 3 );
7 years, 3 months ago

You must be logged in to reply to this topic.