Support

Account

Home Forums Search Search Results for 'taxonomy'

Search Results for 'taxonomy'

reply

  • it still can’t save taxonomy field in option page

  • You can try to add a filter that will select a default value if none is selected already. Perhaps something like this:

    add_filter('acf/load_value/name=your_taxonomy_field_name', 'set_default_taxonomy_selection', 10, 3);
    function set_default_taxonomy_selection($value, $post_id, $field) {
        // Check if the field has a value
        if (!$value && empty($_GET['post'])) {
            // Set the default term ID here
            $default_term_id = 7;
            $value = $default_term_id;
        }
        return $value;
    }
  • Thanks John. I know this isn’t a critical issue, so will mark this solved.

    I’ve determined that Save Terms is required in order for my block editor to reference the terms. So that will be required for me.

    I’ve tested scenarios, enabling and disabling Load Terms, and haven’t run into any issues. So I’ll leave that disabled in the interest of simplicity.

    If there are any videos, blogs, forum posts, etc., that go into the uses cases, I’d be happy to have those to read some more. I believe I understand the use case that a taxonomy is just an object that’s available as a global resource, and this Save Terms lets you define which scenarios (post type and field group) where it’s appropriate. Still a bit foggy on Load Terms.

    Thanks again!

  • Save/Load Terms

    Save terms causes the terms to be added to the post using wp_set_post_terms().

    Load terms means that the values of the field are loaded from the relationship created by the above or when editing a post and adding terms through the WP taxonomy input (like post categories)

    The two settings work together, but there are cases where you might want to use one and not the other.

  • hi John,

    Thank you very much. You wrote „ Adding terms to a taxonomy requires the WP manage_categories permission.“

    In the field settings I gave anyone the right by enabling „add new tags“ (the frontend form is only visible to user role „author“ anyway, so no misuse risk).
    Again: when accessing the form as admin, in accordance with the above setting, I do see a plus sign appear on hover that allows adding tags. But that same plus sign isn’t visible for „author“ role. To me, that doesn’t make sense, because the setting isn’t role specific (I thought).

    How and where can I add the permission you mentioned?

    Best, Ralph

  • Adding terms to a taxonomy requires the WP manage_categories permission.

    Your choices are limited.

    You could edit roles and give everyone this permission, but that’s probably not a good choice.

    I might be possible to give this permission temporarily when viewing a specific page. I’m now 100% sure about this or how it can be done.

    And the last choice is to include a separate text field that is only shown when a user does not have the correct permission using the acf/prepare_field filter and then adding an acf/save_post filter that will add the term to WP and then set it as a post term.

  • IMPORTANT UPDATE [2]:
    Good news regarding to my comment here mentioning that the filter “removed other random metaboxes of other plugins”: I can confirm that it was just a bug with the specific plugin (I also reported that to the plugins developer) and it was NOT related to this fix, as I was encountering the problem randomly, even this filter completely removed from the website. So again, this fix solves the original problem without any side effects!


    @webdvp
    : You are welcome, I created this thread for this reason, to help others!


    @hube2
    : I can confirm that there seems to be no issues with this fix. I contacted your dev team to move forward to a fix.

  • Yes, I think that seems to work for me now. So, it looks like a new “page” must be created in WP with the same slug as the taxonomy. In my above example, I created a new page with a slug course_categories. Then, that got tied up to page.php template instead of returning the “page not found”. I could also create a new template page-{taxonomy}.php.

  • The only way to do this in WP is to create a “Page” with a “Custom Template” and then generate the content yourself.

    If you look at the WP template hierarchy there is no available file to create this list of terms automatically.

    Generally, taxonomy terms are listed on the post archive page.

    As an example, WooCommerce has a CPT for product and a Custom Taxonomy for product categories. When you view the “Shop” page a list of categories or sub categories is shown with links to those categories followed by a list of products in the current category when a specific category is shown.

  • Sorry, I just realized what’s going on.

    There is no page for https://example.com/course_categories/, or https://example.com/{$taxonomy}/, this is not a valid page in WP. Archive pages only list posts in a specific term. In other words, there is no page in WP that will list all of the terms in a taxonomy.

  • I have been noticing an issue with this.

    When I generated the PHP code from ACF > Tools > Export, I could not see any “archive” key/value field in the PHP code.

    I created a hierarchical taxonomy called ‘course_categories’. It generates the category URLs like these:
    https://example.com/course_categories/craft/ <- working
    https://example.com/course_categories/craft/jewellery/ <- working

    However, this link: https://example.com/course_categories/ always returns page not found.

    How do I resolve this?

  • Dude I have created an account just to say thank you! I tortured myself today with finding a solution for removing the taxonomy meta box.

  • The filter you posted is passing $taxonomy, check the taxonomy name to ensure it matches your custom taxonomy before making the changes?

    This is just a guess

  • If you are using ACF to create the taxonomy

    Advanced Settings => Visibility => Meta Box => No Meta Box

  • The requires altering the permalink structure for your CPT and Taxonomy using a combination of add_rewrite_rule(), query_vars, add_rewrite_tag() and add_permastruct(). It can be a complex project. You will need to look for information on using these functions.

  • Is this on a post? Options? Taxonomy?

    You need to build a CRON that looks at wherever the values are stored and checks the dates and then removes them if they are past.

    For example if these fields are on some type of post then the cron needs to do a query that gets all of the posts that have values in this field, loops over those posts, checks the date and then updates or removes the field value.

    https://developer.wordpress.org/plugins/cron/

  • The only way to do this (if it is possible) is to alter the permalink structure for your CPT and Taxonomy using a combination of add_rewrite_rule(), query_vars, add_rewrite_tag() and add_permastruct().

  • hi all,
    i am doing this now for days and finally it worked out with ACF repeater field called “galleryx” which holds two ACF fields

    1. “gallery_tags” a ACF Taxonomy field (return value term id)
    2. “gallery_images” a ACF image field (return value url)

    All work fine when done manyually on my Custom Post Typ “projekte”…also when inmporting as defined by you guys for example one projects adds up 8 image rows..all other project data is also fine if couting their proper rows…also the data seems to be saved like “tagname, tagname”, “imagefile-name” and so on. but just the image is emplty and tags are not checked..i think because its not converted into the taxonomies needed object / serialization etc.

    this i my function:

    <?php
    add_action( 'pmxi_saved_post', 'soflyy_add_data', 10, 3 );
    
    function soflyy_add_data( $id, $xml, $update ) {
    
        // Parent field name.
        $selector = 'galleryx';
    
        // The field to be appended.
        $subfield1 = 'gallery_image';
    	$subfield2 = 'gallery_tags'; 
        
        // Only continue if my_repeater_data contains a value.
        if ( $value1 = get_post_meta( $id, 'my_repeater_data_gallery_image', true ) ) {
            $value2 = get_post_meta( $id, 'my_repeater_data_gallery_tags', true );
    			
            // Format data for repeater.
            $row = array( $subfield1 => $value1, $subfield2 => $value2 );
    
            // Add new repeater row.
            add_row( $selector, $row, $id );
    
        }
        delete_post_meta( $id, 'my_repeater_data_gallery_image' );
    	delete_post_meta( $id, 'my_repeater_data_gallery_tags' );
    }
    ?>

    what do you think?
    thanx so much
    timo

  • I came up with the following solution:

    function custom_accreditation_logo () {
    	ob_start();
    		$queried_object = get_queried_object(); 
    		$post_id = $queried_object->ID; 
    		$terms = wp_get_post_terms( $post_id, 'accreditations' );
    		//$terms = get_terms( array( 'taxonomy' => 'accreditations', 'hide_empty' => false ) );
    		echo '<div class="acc_logos">';
    		foreach ( $terms as $term ) {
    			$image = get_field('featured_image', 'accreditations_' . $term->term_id );
    			echo '<img src="' . $image['url'] . '" alt="' . $image['alt'] .'">'; 
    		}
    		echo '</div>';
    	$content = ob_get_clean(); // store buffered output content.
    	return $content;
    }
    
    add_shortcode( 'accreditatie_logos', 'custom_accreditation_logo' );
  • In the taxonomy subfield, setting the return value from Term id to Term object solved the issue.

  • Just in case it can help someone, I was able to accomplish this perfectly for my situation using Elliot’s select2_ajax_data filter suggestion and it’s much simpler than the other methods it seems. I have two taxonomy dropdowns and needed the 2nd one to be filtered by the value of the 1st one. @oscarfanatic ‘s solution got me pointed in the right direction and some other code I found online helped clear the rest up.

    Also want to tag @hube2 in case it can help with his awesome efforts of helping people out in the forums.

    Here’s how it works:

    add_action( 'acf/input/admin_footer', function() {
    	?>
    	<script>
    		( function( $ ) {
    			if ( typeof acf !== 'undefined' ) {
    				acf.add_filter( 'select2_ajax_data', function( data, args, elem, field, instance ) {
    					if ( 'field_648b0852a2448' === data.field_key ) {
    						data.format_id = $( '#acf-field_648b0890a2462' ).val(); // format_id is a custom property being added to the data object. It can be named whatever you want.
    					}
    					return data;
    				} );
    			}
    		} )( jQuery );
    	</script>
    	<?php
    } );
    
    add_filter( 'acf/fields/taxonomy/query/key=field_648b0852a2448', function( $args, $field, $post_id ) {
    	$format_id = $_POST['format_id'] ?? false; // $_POST['format_id'] is the custom property you created in the javascript above
    	if ( $format_id ) {
    		$args['meta_key'] = 'format';
    		$args['meta_value'] = $format_id;
    	}
    	return $args;
    }, 10, 3 );
  • So I was searching for how to do this and this support doc was the first result on Google. I have a case where we set-up custom fields for the admins to sort in the dashboard but now want to convert the fields to a taxonomy in order to display as categories on the front end. I ended up working with ChatGPT for an hour starting with this framework and have achieved this result–which surprisingly seems to work as expected. But I wanted to post it here not only because it is a potential solution for other users seeking this out, but also because I am a systems integrator more-so than a formal developer and I am wondering what more expert folks would make of this work? Is it sound?

    function convert_field_to_terms() {
        if (!is_admin()) {
            return; // Only run on the frontend
        }
    
        $args = array(
            'post_type' => 'portfolio',
            'posts_per_page' => -1,
        );
        $query = new WP_Query($args);
        if ($query->have_posts()) {
            while ($query->have_posts()) {
                $query->the_post();
                $acf_value = get_field('admin_theme');
                if ($acf_value) {
                    $term_ids = array(); // Array to store term IDs
    
                    if (!is_array($acf_value)) {
                        $acf_value = array($acf_value); // Convert to array if it's not already
                    }
    
                    foreach ($acf_value as $value) {
                        $term = get_term_by('name', $value, 'public-theme');
                        if (!$term) {
                            $term_args = array(
                                'slug' => sanitize_title($value),
                            );
                            $term = wp_insert_term($value, 'public-theme', $term_args);
                            if (!is_wp_error($term) && isset($term['term_id'])) {
                                $term_ids[] = $term['term_id']; // Add the term ID to the array
                            }
                        } elseif (!is_wp_error($term)) {
                            $term_ids[] = $term->term_id; // Add the term ID to the array
                        }
                    }
    
                    wp_set_object_terms(get_the_ID(), $term_ids, 'public-theme', false);
                }
                update_post_meta(get_the_ID(), 'state_update_complete', '1');
            }
        }
        wp_reset_postdata();
    }
    add_action('init', 'convert_field_to_terms');
    
  • I have not used the CPT/Custom taxonomy feature for ACF, so I don’t know how to add columns.

    But sorting by those columns in not something that is supplied by any CPT plugin that I know of. This is something that requires adding filters and functions to WP. Her is one example https://wordpress.stackexchange.com/questions/293318/make-custom-column-sortable

  • You need to get the taxonomy terms associated with the related posts and loop over them

    
    <?php 
    $linked_organisation = get_field('linked_organisation');
    if ($linked_organisation) {
      foreach ($linked_organisation as $l) {
        $terms = get_post_terms($l->ID, 'YOUR TAXOMY HERE');
        if ($terms) {
          foreach ($terms as $term) {
            // get fields from term
            get_field('FIELD NAME', $term);
          }
        }
      }
    }
    
  • Hi Noëlle,

    This is not an answer, but I was looking up how to add the taxonomy columns to the admin – what did you use to do it?

    Ben

Viewing 25 results - 676 through 700 (of 3,193 total)