Types is a WordPress plugin that lets you easily create custom taxonomies and organize your custom content types in your website.
When you ask for help or report issues, make sure to tell us what you have created so far and what you want to achieve.
Viewing 13 topics - 151 through 163 (of 163 total)
Problem: I am creating an Artist directory and gallery site that provides artists the ability to upload their own artwork images. I have created a Form that allows artists to upload multiple images into a repeating image field. I would like to give artists the ability to apply taxonomy terms to each image in the custom field.
Solution: It is not possible to apply terms to each image uploaded in a repeating custom image field. If you need the ability to add taxonomy terms, you probably need a separate custom post type. Artists can then use Forms to create a new post for each "Artwork", and apply taxonomy terms as needed to that post.
Problem: I have a Form used to create posts. There is a taxonomy field in the Form so Users can choose which term(s) to apply to the new post. I would like to display only terms that were created by the current logged-in User.
Solution: Since WordPress does not natively track the author of each term, you must programmatically add that term author ID in a custom field associated with each term when the term is created. Once that custom field value is added successfully, you can then use the get_terms hook to filter the terms available in the taxonomy field options. Here is an example of the code:
// RESTRICT TAXONOMY TERM FIELD OPTIONS TO USER'S OWN TERMS BY TERM FIELD VALUE
// https://toolset.com/forums/topic/show-only-terms-created-by-current-user-in-taxonomy-dropdown-on-the-form/
function tssupp_terms_by_current_user( $terms, $taxonomies, $args, $term_query ){
$pages = array( 123, 456 ); // comma-separated list of page IDs where this Form is displayed
$taxonomy_slug = 'tax-slug'; // slug of the taxonomy to filter
$author_field_slug = 'field-slug'; // slug of the post author id field
// you should not edit below this line
// loop over each term and get its custom field value
// compare that field value against the current user id and drop any terms with a different value
$user_id = get_current_user_id();
if ( is_page( $pages ) && $taxonomies[0] == $taxonomy_slug ) {
foreach($terms as $key=>$term) {
$term_author = get_term_meta($term->term_id, 'wpcf-' . $author_field_slug, true);
if( $term_author != $user_id ) {
unset( $terms[$key] );
}
}
}
return $terms;
}
add_filter( 'get_terms', 'tssupp_terms_by_current_user',10,4);