Customize the output of dynamic tags

We really need a possibility to customize the output of dynamic tags more.

Example one:
I use: " Sprache: {post_terms_pa_sprache}" for displaying the languages a product is available in (Woocommerce). This leads that the languages are links automatically, but I need to deactivate these links, so only the name is printed.

Second example:
It also holds true for ACF fields. I was trying to add a custom attribute, which should return an ACF field value.
Name => artist || Value => {acf_ausstellung_to_artist}
The idea is to be able to use it for filtering e.g. via Isotope.
The issue now is that I cannot control the output whatsoever. I need that only the name of the field is rendered in the attribute,

But on the frontend it outputs the following:
“artist=“Rudi Frey””

We really need a possibility to customize that output.
E.g. be able to type {acf_ausstellung_to_artist:name} => which only outputs the name etc.

You can already do that in bricks:

See under advanced!

Thanks for your answer.
That would mean that I need to write a custom function for every field I want to output. Or do I miss something there?
It would be helpful to make the dynamic data filters work with acf fields as well and add a :name and :value filter option.

Yes I understand what you want to have and probably it’s a good idea to have it more integrated (also with MetaBox of course :smiley: ). Maybe you can add it to the idea board as I think it won’t have that high priority because of the function callback option we already have there.

You wouldn’t need to create a function for every field. What you need to do is create a function which takes the field-id as parameter (since I’m a metabox user i don’t now the exact function names of ACF you probably have to look up which function is responsible for returning the value), it could look like this:


function get_ACF_fieldValue($fieldname)
// I think it's called get_field in ACF to retrieve the field, but probably you need to use another function
return get_field($fieldName)
}

in bricks you could then use

{echo :get_ACF_fieldValue('YOURFIELDID')}

That should work as a global function and you don’t need to write a function for each field! :wink:

Hope that helps meanwhile!

GrĂŒĂŸe

1 Like

What is the output of {acf_ausstellung_to_artist:text value} ?

Thanks for your suggestion.
I have tried:
{echo: get_ACF_fieldValue(‘ausstellung_to_artist’)}

<?php

function get_ACF_fieldValue($fieldname){
// I think it's called get_field in ACF to retrieve the field, but probably you need to use another function
return get_field($fieldname);
}

And it generates a critical error. Think have to play around more

Hello, thanks for your help!
It sadly ignores the filter and output: "artist="<a href="https://staging.fotohof.org/?kuenstlerinnen=rudi-frey" aria-label="Read more about Rudi Frey">Rudi Frey</a>""

Oh yeah sorry it was not ment to be used directly.

I hardly know anything about ACF and I’m not even sure if that get_field() function exists or if its called slightly different. You would have to look in their docs.

One of these functions should do the trick

No problem :slight_smile: Was just trying if we would be lucky. The get_field function is the right one, but I guess it cannot be used so easily. Could also be as this field is a relationship field, that it be used somehow within the loop. Sadly I am not that advanced in coding yet.

Post on ACF forum. I am pretty sure you will get a solution there.

1 Like

Hmm I wish I could help you :smiley:

If i know hardly anything about ACF I don’t know anything about relationships in ACF 
 But what you could try to do is to navigate on that page where you want to use that dynamic data and kind of debug it inside a code-elemnt of bricks.

first code to test is

echo get_field('YOURFIELDI');

if that outputs something you can try to output the function like so:

function get_ACF_fieldValue($fieldname){

return get_field($fieldname);
}
echo get_ACF_fieldValue('YOURFIELDID');

if that also works then the only thing that could be wrong in using it with dynamic data is that you placed the function at the wrong place. I would recommend you to use the child-theme or a plugin like WPCodeBox, Code-Snippets and so on.

Thanks very much for your help! It’s a really great community here :slight_smile:

I have played around a bit, and I got following to work (It is the specific function)

{echo:get_artist_list_for_attribute}
<?php

function get_artist_list_for_attribute(){


$featured_posts = get_field('ausstellung_to_artist');
if( $featured_posts ): ?>
<?php $my_list = array(); ?>
    <?php foreach( $featured_posts as $featured_post ): 
        $title = get_the_title( $featured_post->ID );
        $custom_field = get_field( 'field_name', $featured_post->ID );
        ?>
            <?php $my_list[] = $title; ?>
    <?php endforeach; ?>

<?php $str = implode (" ", $my_list); ?>


<?php endif; ?>


<? 
return $str;
}

My guess it that the ACF needs the whole loop, because of the relationship field, for outputting on the front end.
Now the output is as wished:

artist="Fritz Macho"
1 Like

Coool stuff → that’s what I ment with "I don’t know too much about ACF, probably your field-type requires a loop, can’t imagine that a single text field would also need a loop!)

I’ve adapted your snippet to make it more dynamically. Now you could use {echo: get_artist_list_for_attribute('FIELDID')} to reuse that function on every field of the same type!

Please let me know if that also works! :wink:

1 Like

@wolfgang

Great! Thanks a lot. Yes, it works flawlessly.

For other readers: ACF return format must be set to “Post Object”.

{echo:get_name_list_from_acf_relationship_field('ausstellung_to_artist')}


<?php

function get_name_list_from_acf_relationship_field($fieldname){


$featured_posts = get_field($fieldname);
if( $featured_posts ): ?>
<?php $my_list = array(); ?>
    <?php foreach( $featured_posts as $featured_post ): 
        $title = get_the_title( $featured_post->ID );
        $custom_field = get_field( 'field_name', $featured_post->ID );
        ?>
            <?php $my_list[] = $title; ?>
    <?php endforeach; ?>

<?php $str = implode (" ", $my_list); ?>


<?php endif; ?>


<? 
return $str;
}
4 Likes