Home › Forums › Backend Issues (wp-admin) › get_field_object() doesn’t work inside columns when custom filter applied
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. I
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_two':
var_dump( get_field_object('field_5b0be1c83f5b4');
break;
endswitch;
}
You need to include $post_id when calling the function in this case
get_field_object('field_5b0be1c83f5b4', $post_id)
before filter
if ($colname === 'calendar_specialist') {
var_dump(get_field_object("field_653638ad2ee77",$post_id)["choices"]);
}
after filter
I get NULL
Columns: email, phone, …
The code works fine if you get the value via
if ($colname === 'calendar_user_email') {
echo get_post_meta($post_id, "group_consultations_email", true);
}
Are there any options to check differently why this works?
I also want to add my msg that after applying the filter, get_field() does not work
I had to use a different function get_post_meta ()
Maybe I have some kind of error in the code that we are blocking acf functions.
add_filter(‘parse_query’, ‘ConsultationsSearchQuery’);
function ConsultationsSearchQuery($query)
{
global $pagenow;
if (is_admin() && 'edit.php' == $pagenow) {
if (
'consultations' == $_GET['post_type'] &&
isset($_GET['calendar_date_start']) &&
isset($_GET['calendar_date_finish'])) {
if ($_GET['calendar_date_start'] && !$_GET['calendar_date_finish']) {
$meta_query = array(
[
'key' => 'group_consultations_date',
'value' => $_GET['calendar_date_start'],
'compare' => '>=',
'type' => 'DATE'
],
);
}
if ($_GET['calendar_date_finish'] && !$_GET["calendar_date_start"]) {
$meta_query = array(
[
'key' => 'group_consultations_date',
'value' => $_GET['calendar_date_finish'],
'compare' => '<=',
'type' => 'DATE'
],
);
}
if ($_GET['calendar_date_start'] && $_GET['calendar_date_finish']) {
$meta_query = array(
[
'key' => 'group_consultations_date',
'value' => [$_GET['calendar_date_start'], $_GET['calendar_date_finish']],
'compare' => 'BETWEEN',
'type' => 'DATE'
],
);
}
$query->set('meta_query', $meta_query);
}
}
}
I don’t see any reason why the code for your column content should not be working.
I started looking into my code again and found the reason in another place.
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.