Hi guys
Trying to return the values to use as IDs, but sometimes there are 2 words. How can I remove the spaces please?
Hi guys
Trying to return the values to use as IDs, but sometimes there are 2 words. How can I remove the spaces please?
I’ve tried something like this, but using {echo:stripped_weight_name} returned nothing sadly.
function stripped_weight_name() {
$text = get_sub_field(‘species_by_weight_name’, ‘option’);
$stripped_text = str_replace(’ ', ‘’, $text); // Replace spaces with an empty string
return $stripped_text;
}
// whitelist bricks echo
add_filter( ‘bricks/code/echo_function_names’, function() {
return [
‘stripped_weight_name’,
];
} );
Also tried things like :value :raw etc.
@aslotta Any idea at all dude? You’re usually pretty hot with this kinda stuff, haha.
Hey @robp,
your function looks ok if it’s just spaces to replace. But it is not working? What does it return instead?
Why are you using get_sub_field
(instead of get_field
) though? Are you fetching from an ACF repeater?
Best,
André
Thanks dude. It was a sub field in a ACF repeater you see that I needed the value of.
I was hoping bricks {} had a way to return the value without spaces, or a hook I could add perhaps, but couldn’t find much.
It essentially wasn’t returning anything - and when I changed it to check if rows etc. it then returned EVERY result in that repeater, haha.
Thanks
@robp Can you maybe share a link (or even better) a temporary login to the site? I think the answer depends a lot on the total context. So some more insights would help a lot.
Yeah Course thank you.
That’s the page Brixham Fish Market - Trawler Agents - Operating the premier fish auction in England. We supply fuel and ice to fishing and commercial vessels - I am using the item in the frames accordion, and trying to add an attribute to it for the ID to be grabbed from the ACF field It’s actually working - I just really need it without spaces.
Code was in here: Log In ‹ Brixham Fish Market – Trawler Agents — WordPress
https://quickforget.com/s/422b23b18931fac45df1ce8797ee4a95e5f8a5896b57f251
The details will vanish once you view that URL FYI.
For anybody looking, André sorted this for me:
add_filter('acf/load_field/name=boat_name', 'acf_load_hake_field');
function stripped_weight_name() {
$loop_object = \Bricks\Query::get_loop_object();
// return str_replace(' ', '', $loop_object['species_by_weight_name'] );
return sanitize_title( $loop_object['species_by_weight_name'] );
}
(then obviously you must whitelist the function in Bricks)
add_filter( 'bricks/code/echo_function_names', function() {
return [
'stripped_weight_name',
];
} );