Do you have a reason not to use a taxonomy for this?
https://codex.wordpress.org/Taxonomies
If your figures connected to taxonomies, then you can filter by tax_query
Your query has to look like this:
// filter on figures from serie's taxonomy
$args = array(
'post_type' => 'figure',
'posts_per_page' => -1,
'meta_key' => 'release_date_fr',
'orderby' => 'meta_value',
'order' => 'DESC',
'tax_query' => array(
array(
'taxonomy' => 'serie', // taxonomy name
'field' => 'slug', // term_id, slug or name
'terms' => array( 'the-legend-of-zelda', 'hyrule-warriors' ), // single value or array of term id(s), term slug(s) or term name(s)
)
)
);
// query the figures
$the_query = new WP_Query($args);
BTW: If there is a error 500, then there is a new entry in you error logs, with more details about the error. Always start at this point to look for a solution.
Hi Gummi!
Thank you! You have absolutely right!!!
Now work well.
I have set the variable inside the while, using get_sub_field because it’s inside of one Repeater Field. $category = get_sub_field('latest_news')
.
Also I have set the Taxonomy Filed inside the post.
And the 'category_name' => $category->slug,
work perfectly!
Thank you so much!
Assuming your “category” field is a taxonomy field and the return type is term_id. then you can try:
$events = tribe_get_events(
array(
'eventDisplay'=>'upcoming',
'posts_per_page'=>-1,
'tax_query'=> array(
array(
'taxonomy' => 'tribe_events_cat',
'field' => 'term_id',
'terms' => get_field('your_category_field_name')
)
)
) );
Assuming your field ‘latest_news’ is taxonomy field with single selection and returning the term object.
the ‘category_name’ is actually not name, it’s the slug. (i know… it’s confusing :/)
https://codex.wordpress.org/Class_Reference/WP_Query#Category_Parameters
So, you query should be:
$category = get_field('latest_news'); // change your variable name so it doesn't confuse yourself
$posts = get_posts(array(
'posts_per_page' => 2,
'post_type' => 'post',
'category_name' => $category->slug, // this is using slug, not name
'cat' => $category->term_id // or you can do this instead
));
Cheers
@fountain I can confirm it works. However, after you update the field, you also have to manually attach the user id to the terms ids in the wp_term_relationship table using wp_set_object_terms(). Otherwise the terms ID’s will be meaningless. WordPress won’t understand those terms are associated with the user.
Also, I’m not sure but you may need to pass the updated field value as an integer and not a string. Maybe also as an array. I’m not sure what update_field checks for.
In my case, I have several terms that I need to associate with each user.
Here’s what I’m using and it works. Keep in mind I’m hooking into gform_user_registered so I can access data submitted through the Gravity Forms user addon form ($feed and $entry, respectively). Sorry for the sloppy comments below, I’m in a bit of a hurry:
add_action( 'gform_user_registered', 'wda_add_expertise', 10, 4 );
function wda_add_expertise($user_id, $feed, $entry) {
$terms = rgar( $entry, '7' ); //get Gravity Forms multiselect field values.
if ($terms) {
// An array of IDs of categories we want this user to have.
$cat_ids = json_decode($terms); // must convert Gravity Forms json to array of integers
// Update ACF
update_field('ares_of_expertise', $cat_ids, 'user_' . $user_id);
// Connect terms with user
/*
* If this was coming from the database or another source, we would need to make sure
* these were integers:
*/
$cat_ids = array_map( 'intval', $cat_ids );
$cat_ids = array_unique( $cat_ids );
// Connecting taxonomy ID's for custom taxonomy "expert" to user ID
wp_set_object_terms( $user_id, $cat_ids, 'expert' );
}
}
one important question is, are the user entering their quite themselves or the site’s admin is going to do it.
If it’s the site admin, then i’d say it’s save to create three custom taxonomies for “publication name”, “related stories ID” and “publication author”.
If you just don’t like how the taxonomy meta box is on the sidebar. you can set the taxonomy “public” value to false when you registering, and use acf’s taxonomy field in stead.
So,
1) it’s be faster to query the quote under “publication name” instead of checking against the meta table
2) because they are taxonomy, you can check the existing ones or add new one on the fly.
Cheers
Maybe some code from my current project will help. I don’t dynamically generate the content of the second field in php when the page is loaded. Since you’re familiar with my other examples.
This is a cut down version of the JS file. I have 2 actions, one to initialize the sub category field and one when the category field changes. The init field basically just hides the sub category field if there is no selection in the category field. There is a line near the bottom where I trigger the init action when the page is loaded.
jQuery(document).ready(function($) {
if (typeof(acf) == 'undefined') {
return;
}
var CMACF = acf.ajax.extend({
events: {
// initialize product sub category field
'init [data-key="field_59dcc174f734c"] .acf-input select': 'init_product_sub_category',
// change sub categories on category select
'change [data-key="field_59dcc100f734b"] .acf-input select': 'change_product_category',
}, // end events
change_product_category: function(e) {
var category = e.$el.val();
//console.log(category);
// clear current sub category
$('[data-key="field_59dcc174f734c"] .acf-input select').val('');
var action = 'get_product_sub_categories';
var self = this;
var data = this.o;
data.action = 'cm_get_product_sub_categories';
data.category = category;
data.exists = [];
this.request = $.ajax({
url: acf.get('ajaxurl'),
data: acf.prepare_for_ajax(data),
type: 'post',
dataType: 'json',
success: function(json) {
console.log(json);
var $select = $('[data-key="field_59dcc174f734c"] .acf-input select');
if (!json || json.length == 1) {
// hide sub category select
$select.closest('.acf-field').css('display', 'none');
return;
}
// clear all selections from sub category select and replace with new values
$select.empty();
for (i=0; i<json.length; i++) {
$select.append('<option value="'+json[i]['value']+'">'+json[i]['label']+'</option>');
}
// make sure the field is visible
$select.closest('.acf-field').css('display', 'block');
},
error: function(jqXHR, textStatus, error) {
console.log(jqXHR);
console.log(textStatus);
console.log(error);
}
}); // end request
}, // end change_product_categoty
init_product_sub_category: function(e) {
// if catetory has a selection and that category has children show field
// otherwise hide the field
var category = $('[data-key="field_59dcc100f734b"] .acf-input select').val();
//console.log(category);
if (category == '') {
e.$el.closest('.acf-field').css('display', 'none');
e.$el.val('');
}
var action = 'get_product_sub_categories';
var self = this;
var data = this.o;
data.action = 'cm_get_product_sub_categories';
data.category = category;
data.exists = [];
this.request = $.ajax({
url: acf.get('ajaxurl'),
data: acf.prepare_for_ajax(data),
type: 'post',
dataType: 'json',
success: function(json) {
//console.log(json);
if (!json || json.length == 1) {
e.$el.closest('.acf-field').css('display', 'none');
e.$el.val('');
return;
}
},
error: function(jqXHR, textStatus, error) {
console.log(jqXHR);
console.log(textStatus);
console.log(error);
}
}); // end request
}, // end init_product_sub_category
});
$('[data-key="field_59dcc174f734c"] .acf-input select').trigger('init');
});
This is the function that dynamically loads the choices of the sub category in php, as you can see by this, if nothing has been saved for the top level category field it returns and empty array for choices.
function load_product_sub_category_field($field) {
global $post;
if ($post && isset($post->ID) && get_post_type($post->ID) == 'acf-field-group') {
return $field;
}
$post_id = $post->ID;
$category = intval(get_field('field_59dcc100f734b', $post_id));
$choices = array();
$terms = array();
if ($category) {
$args = array(
'taxonomy' => 'product-category',
'parent' => $category,
'hide_empty' => false
);
$terms = get_terms($args);
}
if ($terms && !is_wp_error($terms)) {
foreach ($terms as $term) {
$choices[$term->term_id] = $term->name;
}
}
$field['choices'] = $choices;
return $field;
}
We can do this because when the post is saved ACF does not validate the value submitted for the field against the choices of the field. You’ll also notice that I don’t do this on the field group editor page. When I created this select field what I entered for choices is this will be dynamically generated
. So choices are only added to this field if
1) The post has already been saved and there is a value in the field this depends on
OR
2) When something is selected for the category and the field is dynamically populated using AJAX
And finally, this is the function called in the AJAX request
function get_product_sub_categories() {
if (!wp_verify_nonce($_POST['nonce'], 'acf_nonce')) {
echo json_encode(false);
exit;
}
$check_fields = array(
'category'
);
foreach ($check_fields as $index) {
if (!isset($_POST[$index])) {
echo json_encode(false);
exit;
}
}
$choices = array(array('value' => '', 'label' => '- Select -'));
if (!$_POST['category']) {
echo json_encode($choices);
exit;
}
$args = array(
'taxonomy' => 'product-category',
'parent' => intval($_POST['category']),
'hide_empty' => false
);
$terms = get_terms($args);
if ($terms && !is_wp_error($terms)) {
foreach ($terms as $term) {
$choices[] = array('value' => $term->term_id, 'label' => $term->name);
}
}
echo json_encode($choices);
exit;
}
Hi @bluesky
Thanks for getting in touch!
I would suggest that you take a look at the following ACF filters that may help:
https://www.advancedcustomfields.com/resources/acf-fields-taxonomy-query/
https://www.advancedcustomfields.com/resources/acf-fields-taxonomy-wp_list_categories/
I hope this info helps.
🙂
Dealing with getting values from and updating values in select2 fields is not really something I’ve tackled. I haven’t quite figured that out yet and I’m always in too much of a hurry when I need it on a project and generally find ways to work around it.
To be honest, I’m not sure that you can alter the values available in the second select2 field. The reason for this is that ACF is doing it’s own AJAX request to get the values that appear there, so in order to substitute your own values you’d probably need to figure out how to make ACF not update the field in the first place, something that I’m not sure is even possible in the first place. Once you do that you’d probably need to look into how to update the select2 choices in the field by calling a select2 method.
I recently had a similar situation where I needed to provide 2 fields for a client that allowed selecting a “Parent” term and a second field to select a “Child” term. This was required to restrict the choices basically so that the client could not screw things up. What I ended up doing was using 2 regular select fields. The first field only shows top level terms in the taxonomy and the second one shows only child terms of the top level term selected. Both fields are required so that they must select a parent and a child term.
Generally, whenever I’m doing complex things like you found in my repo I fall back to using basic fields and coding all the logic myself rather than try to manipulate the ACF select2 fields.
Just a heads up though. The developer is currently looking into adding filters that allow you to manipulate these fields from the JS side https://github.com/AdvancedCustomFields/acf/issues/4
IF anyone is interested, I got it working.
For some reason the field had a random name instead of the one I gave it in the ACF admin screen. I left a little snippet in so you can easily find the field name through debugging. There is probably a better way to do this but I’m not intimately familiar with all things ACF.
Also note that my custom taxonomy is “expert” so change that out for yours.
add_action('edit_user_profile_update', 'wda_connect_user_terms');
add_action('personal_options_update', 'wda_connect_user_terms');
function wda_connect_user_terms($user_id) {
$terms = $_POST["acf"]['field_59eeaa8ebb291'];
// comment in this snippet to find field name
/* $fields = $_POST;
* echo '<pre>';
* var_dump($fields);
* echo '</pre>';
*/
if ($terms) {
// An array of IDs of categories we want this post to have.
$cat_ids = $terms;
/*
* If this was coming from the database or another source, we would need to make sure
* these were integers:
*/
$cat_ids = array_map( 'intval', $cat_ids );
$cat_ids = array_unique( $cat_ids );
$term_taxonomy_ids = wp_set_object_terms( $user_id, $cat_ids, 'expert' );
if ( is_wp_error( $term_taxonomy_ids ) ) {
// put debug code here
} else {
// put debug code here
}
}
}
Hi all,
I installed LH User Taxonomies and created a taxonomy with the suggested snippet in the plugin’s description.
I then created an ACF taxonomy field for user objects. I can save terms via that field on the user edit screen and they save perfectly, but they aren’t able to connect a term object to a user object via the wp_term_relatinoships table – as @elliot mentioned he implemented in ACF 5.4.0, above.
Has any one had any success with this? Is there a good workaround for hooking into the ACF save process like @rowanpurdy suggested?
@arcanepsyche, @jivedig, @lbonner – you guys have any success? Because of Elliot’s updates on this thread I was expecting that part of the process to work natively with ACF.
Okey it returns the following text:
Contacto
string(473) "SELECT wp_posts.ID FROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN (27) ) AND ( wp_postmeta.meta_key = 'region_contacto' ) AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish') GROUP BY wp_posts.ID ORDER BY wp_postmeta.meta_value+0 ASC, wp_posts.post_modified DESC LIMIT 0, 1"
Copiapó
[email protected]
[email protected]
+56 989025280
string(473) "SELECT wp_posts.ID FROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN (29) ) AND ( wp_postmeta.meta_key = 'region_contacto' ) AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish') GROUP BY wp_posts.ID ORDER BY wp_postmeta.meta_value+0 ASC, wp_posts.post_modified DESC LIMIT 0, 1"
Curicó
CentroBudistaOtzerLingCuric%C%B
[email protected]
Subteniente Luis Cruz Martínez 812, Daya Center
+56 982494947
string(473) "SELECT wp_posts.ID FROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN (25) ) AND ( wp_postmeta.meta_key = 'region_contacto' ) AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish') GROUP BY wp_posts.ID ORDER BY wp_postmeta.meta_value+0 ASC, wp_posts.post_modified DESC LIMIT 0, 1"
La Serena
BudismoOtzerLingSerena
[email protected]
Puyehue 611, Alto Peñuelas
+56 994038436
string(473) "SELECT wp_posts.ID FROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN (24) ) AND ( wp_postmeta.meta_key = 'region_contacto' ) AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish') GROUP BY wp_posts.ID ORDER BY wp_postmeta.meta_value+0 ASC, wp_posts.post_modified DESC LIMIT 0, 1"
Santiago
CentroBudistaOtzerLing
[email protected]
Pasaje Traiguen 2420, 7500000 Providencia
+56 9997890
string(473) "SELECT wp_posts.ID FROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN (22) ) AND ( wp_postmeta.meta_key = 'region_contacto' ) AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish') GROUP BY wp_posts.ID ORDER BY wp_postmeta.meta_value+0 ASC, wp_posts.post_modified DESC LIMIT 0, 1"
Valdivia
BudismoOtzerLingValdivia
[email protected]
BellaMente Valdivia, Carlos Anwandter 348
+56 977802320
string(473) "SELECT wp_posts.ID FROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN (28) ) AND ( wp_postmeta.meta_key = 'region_contacto' ) AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish') GROUP BY wp_posts.ID ORDER BY wp_postmeta.meta_value+0 ASC, wp_posts.post_modified DESC LIMIT 0, 1"
Vicuña
OtzerlingVicuna
[email protected]
+56 965804128
string(473) "SELECT wp_posts.ID FROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_postmeta ON ( wp_posts.ID = wp_postmeta.post_id ) WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN (23) ) AND ( wp_postmeta.meta_key = 'region_contacto' ) AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish') GROUP BY wp_posts.ID ORDER BY wp_postmeta.meta_value+0 ASC, wp_posts.post_modified DESC LIMIT 0, 1"
Viña del Mar
BudismoOtzerLingVRegion
[email protected]
3 Poniente 441 local 14-A (entre 5 y 6 Norte), 2520164
+56 956188137
I’m an idiot. Just up-thread on this SAME page I see that the awesome Matt Keys (I use other plugins by Matt) has created this solution!
https://support.advancedcustomfields.com/forums/topic/conditional-logic-using-taxonomy-field/page/3/
Very long thread so sorry if this has already been suggested… but I was wondering about this too and my first thought was… why not use a Select field instead of a Taxonomy field (where conditional logic is already natively supported) and then use some simple PHP to populate the select field. Like this:
// Programmically Populate an ACF Select Box
function acf_load_type_field_choices( $field ) {
$choices = get_terms( 'battery_type', array('hide_empty' => false) );
if( is_array( $choices ) ) {
foreach( $choices as $choice ) {
$value = $choice->slug;
$label = $choice->name;
$field['choices'][$value] = $label;
}
}
return $field;
}
add_filter('acf/load_field/name=type', 'acf_load_type_field_choices');
This is probably not a great solution though because you have the data in two places not… the taxonomy and the select field. Just a thought. Was hoping to think of a clever solution easier than writing a bunch of JS.
Ok thank you for some of your logic help on this.
What I ended up doing is adding code on the single-CPT.php template that does this:
$client_name = get_the_terms(get_the_ID(),'client-name');
$post_author_id = get_the_author_meta('ID');
$term_id = $client_name[0]->term_id;
if(!get_term_meta($term_id,'term_author_id')) {
add_term_meta($term_id, 'term_author_id', $post_author_id, true);
}
So, on the post, it get’s the term from the taxonomy (this post type will only ever have ONE term assigned to it from that taxonomy). Then it checks if the term has the term meta already, and if it doesn’t, it assigns the author ID of that post as the term_author_id value. That way the code only runs if it needs to.
I decided on this method, since when the user creates a post in this post type, they have to also assign an existing term, or create one, and then is redirected to that post after creation. So that single template file will load immediately after the post is created, this code will run, and everything seems to be working as intended.
My current issue is in the ACF field where the user picks the Taxonomy Term, it is pulling in ALL of the terms still. I have written code to only show terms in other areas:
$taxonomy = 'client-name';
$terms = get_terms($taxonomy, array(
'hide_empty' => false,
'meta_key' => 'term_author_id',
'meta_value' => get_current_user_id()
));
This works great to only display the terms for the logged in user in other areas… and I thought I saw a WP filter that I could apply this logic to EVERYWHERE the terms would be displayed… but now I can’t find it.
Any idea on how this could be done in the ACF field at least?
Perhaps this?
https://www.advancedcustomfields.com/resources/dynamically-populate-a-select-fields-choices/
Or is there a better way?
Are you trying to update a field that is associated with a taxonomy/term or are you trying to update an ACF Taxonomy field? I can’t really tell from your explanation.
Hey @benheath
It would be great if there was a hook we can tap into each time a new Taxonomy was created. That process is being done with JavaScript, and I don’t know of any hook at that step. But that would present another issue… the User could end up not using the Term in the end… so that would need more thinking anyway.
With that said… I asked myself these questions..
I know it would be easy to run add_term_meta() on ‘save’… that’s not an issue.
What I would like to know is…
1) How would we know if a term has been newly added by this User?
2) Can we assume that if ‘term_author_id’ is NOT set, it’s new? Probably.
So… after a Post is Published/Saved… even within the wp_insert_post hook, we can:
Iterate through all terms attached to *that* post. Look for ones that don’t have term_author_id set, and assume (safely) that the current User came up with that term.. then we run run add_term_meta() function.
I don’t have the exact code for you… but do it bit by bit, and use var_dump each step of the way to see if you are getting what you are supposed to.
Here’s a good reference: https://www.smashingmagazine.com/2015/12/how-to-use-term-meta-data-in-wordpress/
Also… there are heaps of functions specific to Terms/Taxonomies for WordPress… get_terms and get_the_terms seem to be good choices here.
Sorry that I couldn’t be more help, but this should get you moving along further I hope!
The goal is to add the user ID as term meta when a term of a custom Taxonomy is created.
Since I’m using an ACF field for the frontend user (logged in only) to be able to add terms if needed, I thought the acf/save_post hook might be easiest. I’m just unsure of how to exactly write the code.
I am good with editing php, if I have an example of something close to what I’m wanting… but I’ve just been coming up empty on this particular need.
$term_id = Not sure where I'd get this from within a hook during term creation.
if ($term_id is new) {
$user_id = get_current_user_id();
add_term_meta($term_id,$user_id,'term_author_id',true); //term would be unique, and have unique meta (unique author)
}
I’m not sure I’m even on the right track with my logic.
When a post is being created or edited, if a new term has been created, that’s when I want to add the ID of the user that is doing it as term meta… so that I can later show terms made by that author back to them.
If you could provide an example, or even the exact code you think would do it that would be AWESOME.
Thank you!
Hello @pixeldesignsuk
Am I correct in thinking that you are in fact looking for “Terms” of a “Taxonomy” and not actually the “Taxonomies” of a CPT?
If you are looking for “Taxonomy Terms” (as opposed to Taxonomies) which makes more sense if looking for the “slug”, then you could try this:
$field['choices'] = array();
$terms = get_terms( array(
'taxonomy' => 'custom_taxonomy_name',
'hide_empty' => false,
));
if ( $terms ) {
foreach ( $terms as $term ) {
$choices[$term->slug] = $term->slug . ' : ' . $term->name;
}
}
Reference:
This is where I generally bypass the pretty fields in ACF like post object and relationship fields and instead I opt for dynamically populated select fields. 99% of the time when I use a post object or relationship field I only get the post IDs and don’t use the built in ability of WP to get the actual posts and do all the other work myself. The, with the select fields I create my own AJAX requests through ACF to get the information for other fields. I have some examples of this here https://github.com/Hube2/acf-dynamic-ajax-select-example. I just built a similar set of fields where one select field is only parent terms in a taxonomy and the second select field is dynamically populated with only the child terms of the parent term selected. Might this be possible with ACF alone? Maybe, but it took me a whole lot less time to build it myself than it would have to figure out the hoops I’d have to jump through to use ACF taxonomy fields. I don’t know if that helps you at all.
Following up:
I tried registering the form first with <?php acf_register_form( $settings ); ?> but this did not work either. I’m not sure if I’m entering the code wrong, or if I’m on the wrong path entirely.
Here it is with acf_register_form:
<?php
/**
* Event Submission Form
* The wrapper template for the event submission form.
*
* Override this template in your own theme by creating a file at
* [your-theme]/tribe-events/community/edit-event.php
*
* @since 3.1
* @version 4.5
*
* @var int|string $tribe_event_id
*/
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
if ( ! isset( $tribe_event_id ) ) {
$tribe_event_id = null;
}
?>
<?php tribe_get_template_part( 'community/modules/header-links' ); ?>
<?php do_action( 'tribe_events_community_form_before_template', $tribe_event_id ); ?>
<?php acf_register_form( $settings );
$settings = array(
/* (string) Unique identifier for the form. Defaults to 'acf-form' */
'id' => 'acf-group_59dd13c80be9e',
/* (boolean) Whether or not to create a form element. Useful when a adding to an existing form. Defaults to true */
'form' => false
);?>
<form method="post" enctype="multipart/form-data" data-datepicker_format="<?php echo esc_attr( tribe_get_option( 'datepickerFormat', 0 ) ); ?>">
<input type="hidden" name="post_ID" id="post_ID" value="<?php echo absint( $tribe_event_id ); ?>"/>
<?php wp_nonce_field( 'ecp_event_submission' ); ?>
<?php tribe_get_template_part( 'community/modules/title' ); ?>
<?php acf_form( $options );
$settings = array(
/* (string) Unique identifier for the form. Defaults to 'acf-form' */
'id' => 'acf-group_59dd13c80be9e',
/* (boolean) Whether or not to create a form element. Useful when a adding to an existing form. Defaults to true */
'form' => false
);?>
<?php tribe_get_template_part( 'community/modules/description' ); ?>
<?php tribe_get_template_part( 'community/modules/datepickers' ); ?>
<?php tribe_get_template_part( 'community/modules/image' ); ?>
<?php tribe_get_template_part( 'community/modules/taxonomy', null, array( 'taxonomy' => Tribe__Events__Main::TAXONOMY ) ); ?>
<?php tribe_get_template_part( 'community/modules/taxonomy', null, array( 'taxonomy' => 'post_tag' ) ); ?>
<?php tribe_get_template_part( 'community/modules/venue' ); ?>
<?php tribe_get_template_part( 'community/modules/organizer' ); ?>
<?php tribe_get_template_part( 'community/modules/website' ); ?>
<?php tribe_get_template_part( 'community/modules/custom' ); ?>
<?php tribe_get_template_part( 'community/modules/cost' ); ?>
<?php tribe_get_template_part( 'community/modules/spam-control' ); ?>
<?php tribe_get_template_part( 'community/modules/submit' ); ?>
</form>
<?php do_action( 'tribe_events_community_form_after_template', $tribe_event_id ); ?>
Does the taxonomy field in question have the load terms and save terms options set to Yes?
John,
Can’t thank you enough for the thorough response—I sincerely appreciate it.
If you wouldn’t mind taking a look:
I’ve put together a couple of answers I’ve received from the devs (attached) of the Community Events plugin, as well as some of the resources and documentation they point to.
Additionally, here is the untouched template file that I believe additional fields can be added to:
<?php
/**
* Event Submission Form
* The wrapper template for the event submission form.
*
* Override this template in your own theme by creating a file at
* [your-theme]/tribe-events/community/edit-event.php
*
* @since 3.1
* @version 4.5
*
* @var int|string $tribe_event_id
*/
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
if ( ! isset( $tribe_event_id ) ) {
$tribe_event_id = null;
}
?>
<?php tribe_get_template_part( 'community/modules/header-links' ); ?>
<?php do_action( 'tribe_events_community_form_before_template', $tribe_event_id ); ?>
<form method="post" enctype="multipart/form-data" data-datepicker_format="<?php echo esc_attr( tribe_get_option( 'datepickerFormat', 0 ) ); ?>">
<input type="hidden" name="post_ID" id="post_ID" value="<?php echo absint( $tribe_event_id ); ?>"/>
<?php wp_nonce_field( 'ecp_event_submission' ); ?>
<?php tribe_get_template_part( 'community/modules/title' ); ?>
<?php tribe_get_template_part( 'community/modules/description' ); ?>
<?php tribe_get_template_part( 'community/modules/datepickers' ); ?>
<?php tribe_get_template_part( 'community/modules/image' ); ?>
<?php tribe_get_template_part( 'community/modules/taxonomy', null, array( 'taxonomy' => Tribe__Events__Main::TAXONOMY ) ); ?>
<?php tribe_get_template_part( 'community/modules/taxonomy', null, array( 'taxonomy' => 'post_tag' ) ); ?>
<?php tribe_get_template_part( 'community/modules/venue' ); ?>
<?php tribe_get_template_part( 'community/modules/organizer' ); ?>
<?php tribe_get_template_part( 'community/modules/website' ); ?>
<?php tribe_get_template_part( 'community/modules/custom' ); ?>
<?php tribe_get_template_part( 'community/modules/cost' ); ?>
<?php tribe_get_template_part( 'community/modules/spam-control' ); ?>
<?php tribe_get_template_part( 'community/modules/submit' ); ?>
</form>
<?php do_action( 'tribe_events_community_form_after_template', $tribe_event_id ); ?>
Here is the Events Calendar Themer’s Guide (Community Events is considered an Add-On to The Events Calendar plugin): https://theeventscalendar.com/knowledgebase/themers-guide/
I found the above code in /wp-content/plugins/the-events-calendar-community-events/src/views/community/edit-event.php
Does this make sense? If that is the correct location for the ACF hook, how/where would I place it? The field group I would like to add is titled “Event Proposals” but, for whatever reason, when I use inspector, the div id comes up as “acf-group_59dd13c80be9e” so I’m not sure if that’s what needs to be used in the hook.
I was unsuccessful with the following code:
<?php
/**
* Event Submission Form
* The wrapper template for the event submission form.
*
* Override this template in your own theme by creating a file at
* [your-theme]/tribe-events/community/edit-event.php
*
* @since 3.1
* @version 4.5
*
* @var int|string $tribe_event_id
*/
if ( ! defined( 'ABSPATH' ) ) {
die( '-1' );
}
if ( ! isset( $tribe_event_id ) ) {
$tribe_event_id = null;
}
?>
<?php tribe_get_template_part( 'community/modules/header-links' ); ?>
<?php do_action( 'tribe_events_community_form_before_template', $tribe_event_id ); ?>
<form method="post" enctype="multipart/form-data" data-datepicker_format="<?php echo esc_attr( tribe_get_option( 'datepickerFormat', 0 ) ); ?>">
<input type="hidden" name="post_ID" id="post_ID" value="<?php echo absint( $tribe_event_id ); ?>"/>
<?php wp_nonce_field( 'ecp_event_submission' ); ?>
<?php tribe_get_template_part( 'community/modules/title' ); ?>
<?php acf_form( $options );
$settings = array(
/* (string) Unique identifier for the form. Defaults to 'acf-form' */
'id' => 'acf-group_59dd13c80be9e',
/* (boolean) Whether or not to create a form element. Useful when a adding to an existing form. Defaults to true */
'form' => false
);?>
<?php tribe_get_template_part( 'community/modules/description' ); ?>
<?php tribe_get_template_part( 'community/modules/datepickers' ); ?>
<?php tribe_get_template_part( 'community/modules/image' ); ?>
<?php tribe_get_template_part( 'community/modules/taxonomy', null, array( 'taxonomy' => Tribe__Events__Main::TAXONOMY ) ); ?>
<?php tribe_get_template_part( 'community/modules/taxonomy', null, array( 'taxonomy' => 'post_tag' ) ); ?>
<?php tribe_get_template_part( 'community/modules/venue' ); ?>
<?php tribe_get_template_part( 'community/modules/organizer' ); ?>
<?php tribe_get_template_part( 'community/modules/website' ); ?>
<?php tribe_get_template_part( 'community/modules/custom' ); ?>
<?php tribe_get_template_part( 'community/modules/cost' ); ?>
<?php tribe_get_template_part( 'community/modules/spam-control' ); ?>
<?php tribe_get_template_part( 'community/modules/submit' ); ?>
</form>
<?php do_action( 'tribe_events_community_form_after_template', $tribe_event_id ); ?>
If there’s any other information I can provide, I’d be more than happy to do so.
Thanks so much!
Hi John, The update_field documentation does not address ACF taxonomy field types. I have used the update_field() call with using the ACF taxonomy field key, but I still need to click the Update button through the admin UI in order to link the ACF taxonomy field value to the WP taxonomy value. Could you please provide a code example for taxonomy values.
$dl_ploidy = ‘field_586131d916252’;
$dl_ploidy_value = $seedlingploidy;
update_field($dl_ploidy, $dl_ploidy_value, $post_id);
using the code above, the value is saved to the correct field, and is viewable through the admin interface, but not on front end output that displays the corresponding wp taxonomy value. Once I click update on the admin post screen, the value is displayed in the front end output. Also, if I follow this call with wp_set_post terms, or wp_set_object_terms, I get the same behavior. An example would be really great. Thanks!
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.