Do I paste this in my child-theme functions.php or archive.php?
My personal preference is in functions.php but I don’t suppose there’s no reason why it can’t be in archive.php since the function is specific to archives.
Also, let’s say I need to do this for multiple fields called release, artist, and dropbox (url to a dropbox folder). Do I add those other fields in like this below, or is there a larger section I need to repeat for each field?
Likely a larger section since you want to capture each of those in their own field. Though I don’t think you’ll be able to loop without creating your own form tag, or if you were dynamically creating forms, so they may just look like this in the form template (with the field name and the field
value in the shortcode changing for each one):
[dynamic_text release readonly "andytruetone_get_category_meta field='release'"]
[dynamic_text artist readonly "andytruetone_get_category_meta field='artist'"]
[dynamic_text dropbox readonly "andytruetone_get_category_meta field='dropbox'"]
This also seems very useful, though I’m curious if these scripts conflict at all
If not using a dynamic form tag, then no conflict to be had!
If using the dynamic form tags, the only conflict concern is if you named an ACF field the same as a shortcode function, then it’d try to execute the shortcode instead of retrieving the field value.
and also where to drop in the additional field names.
That documentation is used to pull info from the form’s shortcode and it’s not dynamic. Meaning, if your contact form shortcode would have the values be defined manually like this:
[contact-form-7 id="87c1bf2" title="Download Category" release="The Border" artist="Willie Nelson" dropbox="https://dropbox.com/example"]
Then you could follow that tutorial to get the value of release
which would be manually set to The Border
by doing this with a native text field like this:
[text release default:shortcode_attr]
And then their instruction in adding the filter:
/*
* Register Custom CF7 Shortcode Attributes
*
* @param array $out Sequential array of shortcode attributes
* @param mixed $pairs I don't know lol
* @param array $atts Sequential array of shortcode attributes set
*
* @return array Modified array of shortcode attributes
*/
function custom_shortcode_atts_wpcf7_filter($out, $pairs, $atts) {
$my_attrs = array('release', 'artist', 'dropbox');
foreach($my_attrs as $my_attr) {
if (isset($atts[$my_attr])){
$out[$my_attr] = $atts[$my_attr];
}
}
return $out;
}
add_filter('shortcode_atts_wpcf7', 'custom_shortcode_atts_wpcf7_filter', 10, 3);
Of course, you could make that dynamic in a way by using that filter like this instead:
/*
* Register Custom CF7 Shortcode Attributes
*
* @param array $out Sequential array of shortcode attributes
* @param mixed $pairs I don't know lol
* @param array $atts Sequential array of shortcode attributes set
*
* @return array Modified array of shortcode attributes
*/
function custom_shortcode_atts_wpcf7_filter($out, $pairs, $atts) {
$my_attrs = array('release', 'artist', 'dropbox');
foreach($my_attrs as $my_attr) {
$out[$my_attr] = andytruetone_get_category_meta(array('field' => $my_attr)); // Calls the custom function from above
}
return $out;
}
add_filter('shortcode_atts_wpcf7', 'custom_shortcode_atts_wpcf7_filter', 10, 3);
And then in your form template, it’d be these three:
[text release default:shortcode_attr]
[text artist default:shortcode_attr]
[text dropbox default:shortcode_attr]
(Please note this code is untested, I wrote it directly in this answer block so syntax could be sloppy)