Plugin Support
ying
(@yingscarlett)
Hi there,
The built-in functions of the dynamic data can not pull the user data, if you set the ACF field return value to ID, the headline block will be able to output the ID of the user by setting the dynamic data source to post meta > your field name, but I don’t think it’s able to output the name or adding user archive to it.
It will require custom coding to alter the output, try follow below steps:
- add a CSS class to the headline block, eg.
post-translator. https://wordpress.com/support/wordpress-editor/adding-additional-css-classes-to-blocks/
- add this PHP code, replace
translator with the actual acf field name.
add_filter('generateblocks_dynamic_content_output', function($content, $attributes, $block){
if ( ! is_admin() && ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'post-translator' ) !== false ) {
$post_id = get_the_ID();
$translator_id = get_field('translator', $post_id);
if ($translator_id) {
// Retrieve the user's name
$translator_name = get_the_author_meta('display_name', $translator_id);
$content = esc_html($translator_name);
}
return $content;
}
}, 10, 3);
add_filter('generateblocks_dynamic_url_output', function($url, $attributes) {
if ( ! is_admin() && ! empty( $attributes['className'] ) && strpos( $attributes['className'], 'post-translator' ) !== false ) {
$post_id = get_the_ID();
$translator_id = get_field('translator', $post_id);
if ($translator_id) {
// Retrieve the user's archive URL
$translator_archive_url = get_author_posts_url($translator_id);
$url = esc_url( $translator_archive_url);
}
return $url;
}
}, 10, 2);
Thank you for the quick response!
I think we’re almost there. I placed the class as “additional CSS” (checked via source code) and added the code in the functions.php of my template (using my field name “tradutor”), but unfortunately without success – I only obtained the User ID.
An example: https://www.valinor.com.br/70225 (“TRADUZIDO POR 111441“)
Did I do something wrong?
Best regards, Fabio Bettega
Plugin Support
ying
(@yingscarlett)
The scribe template author name headline is using GP’s dynamic data option, the function is using GB’s, there is a conflict.
Can you use the GB dynamic data in the right sidebar, instead of the dynamic data set in the floating tool bar for that headline? https://app.screencast.com/KQEVbVoxFCbkR