Search results for ""

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

Getting ACF enhanced message field in columns


I’m using an ACF addon plugin “ACF Enhanced Message Field” to execute php in a metabox.
Specifically I use it on a WC product page to get meta-value(s) from a related custom-post “Repair”. So I can see all repairs done on this specific product. Works fine that way and I made the repair numbers clickable to go to the related repair page.
Now I’d like to have these value(s) also in the list mode in a separate column. The values don’t show up if I set up a column with Admin Columns Pro. I choose ACF for content and the field I need.
Is there a way to make this work? Some filter or hook in functions.php?
Thanks sofar, Paul

4 years, 6 months ago

Hi Paul,

I think the best way to achieve this is to create your own column.
Please read this developer guide to create your own column.

Because you already wrote your own logic for the metabox, it would be not that difficult to create your own column.
If you store a repair ID (or maybe multiple id’s) you can use this ID as raw_value. For the display value you can use the same logic as you use for the metabox.

4 years, 6 months ago

Hi Stefan,

Thanks. I use the following code to get the Repair-ID(‘s):

$id = get_the_ID();
						$repairs = get_posts(
							'post_type' => 'repair',
                                                        'meta_query' => array(
									'key' => 'avw_uurwerk',  
									'value' => $id, 
                                                                       'compare' => 'LIKE'
						 if( $repairs ): 
							 foreach( $repairs as $repair ): 
repair number: <a href="/wp-admin/post.php?post=8619&action=edit"><?php echo get_the_title( $repair->ID );?></a> (click to go there)</br>
                                                       <?php  endforeach; 

Not sure how I could “divide” this over the the value and raw_value variables. Looks like the variables store only 1 value.

What do you suggest?

4 years, 6 months ago

Please note that there are two methods in the a column for getting the value

get_value( $post_id ) -> This is the value that wil display the data in the overview
get_raw_value( $post_id ) -> This value is used for sorting, filtering en inline edit.

Markup in get_raw_value() is not wise because you’ll get strange sorting results based on your desired output.
Maybe just a flag (boolean) or the count of repairs is good to as a raw value. In that case you can sort on the count of repairs that are available for a specific post.

For your display value you can wrap the code above into the get_value( $post_id ) method in the new column class. $id can be set as $post_id instead of using get_the_ID(). And instead of echoing the output, you have to return the value in the method.

Be aware that your code will run for every record in the overview and can give you a performance penalty when you show a lot of rows on your overview. Please let me know if you managed to get this working.

Good luck!

4 years, 6 months ago

You must be logged in to reply to this topic.