Hi guys. I created a taxonomy for posts (it is called contributors). I used ACF to add custom fields for the contributors (for example the year when he/she was born). I am using ACF repeater to add multiple contributors to the posts. It works perfectly fine, I am able to list the contributors using Brick’s repeaters, but my goal is to include the birth year of the contributor too (which is an ACF field of the contributors taxonomy). Is that possible with Bricks? I can’t figure it out.
If your repeater contains the year - you can just get it with acf_field_name
If the year is stored outside the repeater, you would need to get the author ID, and then do a sub-query to find the year. I suspect you’d need to use your own function. So within the repeater loop:
{echo:my_function}
and my_function is roughly
function my_function() {
$getID = \Bricks\Query::get_loop_object_id();
$year = get_field(author_dob, $getID);
return $year;
}
Just making that up as i type, but that sort of function.
Thank you for your help @digismith !
“If your repeater contains the year - you can just get it with acf_field_name”
The year is stored outside of the repeater.
I think I set up everything correctly (replaced the name of the ACF field) but if I use this function a critical error message will show up and can’t edit the page template, also on the front end it returns a white page (for the page on the template is applied).
Please could you double check the code? I did everything correctly? The ACF value where the year is stored is called “szuletesi_ev”
function contributor_year() {
$getID = \Bricks\Query::get_loop_object_id();
$year = get_field(szuletesi_ev, $getID);
return $year;
}
Thank you! Really appreciate your help!
Hi, I’m afraid I can’t solve it, I tried recreating your setup… I will just tag @aslotta - who may know the solution.
Otherwise, to be a pain. In trying to recreate - it seems to me you are doing things a difficult way. If instead you had (e.g.)
A custom post type - Contributors
Add your ACF fields to this (e.g. birth year)
Create a relationship to (posts? or the other CPT you are using).
Now you can select multiple contributors - but also access their ACF fields easily.
Sorry I can’t be more help with your question.
I did not read all the thread yet but in your snippet you are missing some important quotes. Also instead of just the ID it might be necessary to pass the whole term object to the get_field
function (according to the example in the documentation):
function contributor_year() {
$contributor = \Bricks\Query::get_loop_object();
$year = get_field( 'szuletesi_ev', $contributor );
return $year;
}
function ds_contributor_year() {
$contributor = \Bricks\Query::get_loop_object();
$contid = implode(',', $contributor );
$year = get_term_meta( $contid, 'szuletesi_ev', true );
return $year;
}
Thanks @aslotta - this got me the rest of the way.
@roundedhexagon
ACF stores the info as TERM META - and I was unable to get it with get_field . Also - the get_loop_object returns an array - which needs to be imploded.
I’m pretty sure this code will get you there- tested and working for me.