Support

Account

Home Forums Search Search Results for 'taxonomy'

Search Results for 'taxonomy'

reply

  • its used like this:

    
    add_action('init', 'UnitedDJ_plugin', 10);
    
    function UnitedDJ_plugin(){	
    	
    	if( !is_admin() )
    		new UnitedDJ();	
    }
    
    class UnitedDJ {	
    	
    	public function __construct(){
    				
    		// Add on acf
    		if( class_exists('acf_field') ){
    			include('classes/acf.class.php');
    		}
    }
    
    class UnitedDJ_acf extends UnitedDJ {
    	
    	public function __construct(){		
    			
    		// general actions
    		add_filter('acf/fields/taxonomy/query', array( $this, 'kies_je_categorieen_args' ) );
    				
    		
    	}
    }
  • I have a similar issue with ACF 4.4.3 in a WYSIWYG field in a custom taxonomy – the text tab does not display and a JS error is thrown.

    I turned on script debug, and the error for input.js occurs on line 199, where it looks like the script is parsing the URL.

    There may be a bigger issue behind the non-rendering – I have a WYSIWYG field in a repeater on a page using a custom template. The text tab is not shown for that field, but there is no JS error in that instance.

  • Just adding to what David has posted. The problem is specifically with fields that store values as arrays that get killed. The reason this happens is that wp_kses_post() expects a string input and returns a string as output.

    The fields that can cause problems are

    • checkbox
    • multi select
    • Any field that allows the selection of multiple values, like a relationship field, a post object field set to allow multiple, a taxonomy field set to allow multiple, etc.

    I’ve been looking and It does not appear that there’s anything that will work on arrays.

  • Yes, there would need to be something if a taxonomy field can have multiple selections, I missed that in your original post

    
    if (have_rows('repeater_field')) {
      while (have_rows('repeater_field')) {
        the_row();
        $name = get_sub_field('name_field');
        $titles = get_sub_field('title_field');
        echo $name->name,': ';
        $count = 0;
        foreach ($titles as $title) {
          $count++;
          if ($count > 1) {
            echo ', ';
          }
          echo $title->name;
        }
        echo '<br />';
      }
    }
    
  • To display the rows of a repeater with taxonomy fields as subfields would look something like this.

    This code assumes that you are returning term objects from the taxonomy fields

    
    if (have_rows('repeater_field')) {
      while (have_rows('repeter_field')) {
        the_row();
        $name = get_sub_field('name_field');
        $title = get_sub_field('title_field');
        echo $name->name,': ',$title->name;
      }
    }
    

    for more information see
    have_rows: http://www.advancedcustomfields.com/resources/have_rows/
    taxonomy field: http://www.advancedcustomfields.com/resources/taxonomy/
    term object: http://codex.wordpress.org/Function_Reference/get_terms

  • Jonathan – thanks for all your assistance and hope everything is ok.

    Disregard this Post. I needed to check the save terms to post option for the taxonomy custom field

    I did as you recommended and the taxonomy does now show the categories that can be selected but these are not put to the post once it is created. I mean the form creates the new posts but they still list as Uncategorized in the post info. The ACF taxonomy field is keeping the selection from the fronted form but I am looking to use the standard WP categories like under each post the theme lists the category associated with that post.

    Thanks
    Andy

  • Totally understand the logic behind it, and agree that the current in-place implementation works as intended! I’ll work on coding a front-end fix that pulls depending on the Grade and Standard selected for the post, instead of just polling every single taxonomy in the post_meta.

    Thank you for the quick follow up.

  • Hi Andy,

    Sorry I’ve been involved in some personal stuff the past few days 🙂

    To be honest I’ve not used the acf_form in this sense before.
    What seems strange to me is that you’re setting post_title, post_content and post_category by using $_POST values but if you’re sending the user to this form with just a button there wont be any $_POST variables like this.

    The way I’d do it is to just have a taxonomy field on the posts which are mapping the post to the terms (categories) and then add it to the acf_form by setting it in the field_group. Then for the title and content you have built in parameters in acf_form to let users type into those.

    Something like:

    
    <?php acf_form(array(
    	'post_id'	=> 'new_post',
    	'new_post'	=> array(
    	   'post_type'	=> 'post',
    	   'post_status'=> 'publish'
    	),
       'field_groups'   => array(317, 123), // 317 is your existing field group and 123 is a madeup which contains the taxonomy field.
       'submit_value'       => 'Submit Post',
       'updated_message'    => 'Saved!'
    )); ?>
    

    You shouldn’t need to mess with $_POST parameters and filters.

  • This seems to be related to this, at least it seems similar. The other bug was just the back end and this one seems to involve the front end as well. Though I could be wrong.

    http://support.advancedcustomfields.com/forums/topic/filter-by-taxonomy-disappears/

    Will see what I can do about getting the developer’s attention.

  • Thanks for the troubleshooting tips Jonathan. I made some tweaks to my selectors and with the following code was able to give the Select2 field focus when a new row is added.

    acf.add_action('append', function( $el ){
    	var $wood = $el.find( '[data-name="bulk_wood"] select');
    	$wood.focus();
    	$wood.select2('open');
    });

    I’m still unable to set the value of the Select2 field though. This next snippets work as expected setting the value of text inputs using data from the previous row. Is it possible to set the value of a Taxonomy field type with the Select2 appearance? I think the AJAX parts are complicating this task.

    acf.add_action('append', function( $el ){
    	var $prev_row = $el.prev();
    	var $wood = $prev_row.find( '[data-name="bulk_wood"] select' ).val();
    	var $thickness = $prev_row.find( '[data-name="bulk_thickness"] input' ).val();
    	$el.find( '[data-name="bulk_thickness"] select' ).append(new Option('text', 'value')); // Not working
    	$el.find( '[data-name="bulk_thickness"] input' ).val( $thickness ); // Works great
    });
  • Hi @philnickel

    No problem!

    To show your value from a specific category in a template you use the second parameter of get_field or the_field which is normally used for post IDs.

    For categories you use
    the_field('fieldname', 'taxonomyslug_categoryid')
    For users you’d use
    the_field('fieldname', 'user_'.$user->ID)

    Etc etc

    so in your case it would be
    the_field('category_beschreibung', 'category_29')

  • I’m still not really sure I’m understanding what you mean. Tell if this is correct.

    1) You have a single post of some kind. For this post you have taxonomy set up and you select a term in this taxonomy for your post. Do you want to show a custom field from this term?

    2) You have a post with a Taxonomy Field and you want to show the name of the Term selected in this field.

    Something else? Sorry, I’m just not getting the relationship between the post and what you want to display.

  • Hello again 🙂

    So I’m within the loop to get the content of a post, on single.php.

    This post has a custom field which is from a custom taxonomy. The custom taxonomy is “ville” and the custom field is “arrondissement”.

    I manage to get the ID of the term. But I would like to output the name of it, not the ID.

    <?php the_field(‘arrondissement’, $term); ?>

  • I thought you were looking for how to get a custom field from a custom taxonomy, but I read it again and you say single.php, so now I’m a bit confused.

    What is the field type and where is the field group shown?
    Is the field group on posts?

  • It’s “ville”

    Doing so, output nothing though:

    $taxonomy = ‘ville’;
    the_field(‘arrondissement’, $taxonomy.’_’.$term->term_id);

  • What is the slug of your custom taxonomy?

    
    $taxonomy = 'your-taxonomy-slug'
    the_field('arrondissement', $taxonomy.'_'.$term->term_id);
    
  • Hi,
    Thanks Jonathan!!!

    This is the final code that solves the issue:

    // Remove taxonomy from the attachment pages so the acf taxonomy can work
    
    function remove_custom_taxonomy()
    {
    	remove_meta_box('YOURTAXONOMYNAMEdiv', 'attachment', 'side' );
    	
          
           
    }
    add_action( 'admin_menu', 'remove_custom_taxonomy' );
    
    // Add this in to remove it from the popup editor
    function attachment_remove_taxonomy( $fields ) {
    		
    		unset($fields['YOURTAXONOMYNAME']); 
    	  return $fields;
    	}
    add_filter( 'attachment_fields_to_edit', 'attachment_remove_taxonomy' );
  • Hi @nhankla

    Have you tried removing the default taxonomy meta box?
    I’m not sure if it’s possible to do with the attachment as those are as you say a bit different but there’s a function called remove_meta_box() that you can try: https://codex.wordpress.org/Function_Reference/remove_meta_box

  • Setting the Relational Post Object to write back to the post (the german translation for this function is not entirely cleat BTW), changing the taxonomy selector to Radio Button (drop down seem to have a bug, as it mixes taxonomies translations) and opening and re-saving every member CPT did the trick, with the following code:

    $tax = get_field_object("department");
    $taxnum = $tax['value'];
    $taxtax = $tax['name'];
    $dept = get_term( $taxnum, $taxtax );
    $deptname = $dept->name;

    Now for the same fun in a repeating field group… yay!

  • Hi @aaronrobb

    Changing in core files is never a good thing since it’ll be overwritten each time you update (and ACF updates are pushed out quite regularly).

    The taxonomy query filter is really only if you want to change what to query, not how the results should look.

    If you’re open to switching to multiselect dropdown I think there’s a few filters you need to use.

    First is the http://www.advancedcustomfields.com/resources/acfload_field/
    Where you’ll want to modify the [‘choices’] array.

    And since it uses AJAX to fetch more taxonomies you need to modify the output there as well using this filter:
    acf/fields/taxonomy/result/name=name_of_field

    which takes these parameters $title, $term, $field, $post_id and should return $title.

    In there you can also check for the users role by doing

    
    $user = wp_get_current_user();
    if ( in_array( 'author', (array) $user->roles ) ) {
        //The user has the "author" role
    }
    
  • Ok, so there is a hack way of doing what I want.

    In taxonomy.php i modified line 1020 from this:

    		// append
    		$output .= '<li data-id="' . $term->term_id . '"><label><input type="' . $this->field['field_type'] . '" name="' . $this->field['name'] . '" value="' . $term->term_id . '" ' . ($selected ? 'checked="checked"' : '') . ' /> <span>' . $term->name . '</span></label>';
    				
    	}

    to this:

    // append
    		$output .= '<li data-id="' . $term->term_id . '"><label><input type="' . $this->field['field_type'] . '" name="' . $this->field['name'] . '" value="' . $term->term_id . '" ' . ($selected ? 'checked="checked"' : '') . ' /> <span>'. $term->slug .'-' . $term->name . '</span></label>';
    				
    	}

    adding in the ‘$term->slug’ in the label span.

    So now a term looks like:

    1132-Forest Nurseries and Gathering of Forest Products

    With 1132 being the slug.

    This isn’t a good solution, since it could get overwritten, so just need to find out how to make that work….
    Especially because I have a second Taxonomy field (different taxonomy) that I don’t want the slug to show up on….

  • Hey Jonathan

    Ok, we could see how the multi-select works.
    What filter would be used to modify this to include the slug?

    And to modify my first post, we only need the one set of terms to show.

    Here’s the filter from the documentation. Is this what we use?

    <?php
    
    function my_taxonomy_query( $args, $field, $post_id ) {
        
        // modify args
        $args['orderby'] = 'count';
        $args['order'] = 'ASC';
        
        
        // return
        return $args;
        
    }
    
    add_filter('acf/fields/taxonomy/query', 'my_taxonomy_query');
    
    ?>
  • Hi @aaronrobb

    Problems are meant to be solved ey 🙂

    I dived into the taxonomy field code and unfortunately it looks like you wont be able to do this when you have it set as checkboxes.

    It might be possible tho if you’re open to change the visuals to multi-select instead? There are some filters one can hook into but none of them are at work on the checkbox layout since that actually uses the wp_list_categories() function from WP core (with a custom walker function).

  • A taxonomy field can either return term object or term id. From what is being displayed I’m assuming that you are returning term id and you should change this to term object. Then you’ll need to loop through the array that’s returned and echo the term names.

    
    $terms = get_field('expertise_new');
    if ($terms) {
        echo '<span class="acf-field">Expertise:</span>
        echo <span class="acf-value">';
        $term_names = array();
        foreach ($terms as $term) {
            $term_names = $term->name;
        }
        echo implode(' | ', $term_names),'</span><br>';
    }
    
  • So what you need to do is get the ACF field, which will return an array of term IDs and use that array to do a WP_Query, similar to what magicstick posted.

    For this you need to set the taxonomy field on the book edit page to return Term ID, if it’s returning Term Object it will be a bit more complicated.

    
    $topics = get_field('topics');
    if ($topics) {
      if (!is_array($topics)) {
        $topics = array($topics);
      }
      $args = array(
        'post_type' => 'quotes',
        'posts_per_page' => 5,
        'orderby' => 'rand',
        'tax_query' => array(
          array(
            'taxonomy' => 'topics',
            'terms' => $topics,
          ),
        ),
      );
      $quote_query = new WP_Query($args);
      if ($quote_query->have_posts()) {
        while($quote_query->have_posts()) {
          $quote_query->the_post();
          echo '<p>',get_the_content(),'</p>';
        }
      }
      wp_reset_postdata();
    }
    
Viewing 25 results - 2,401 through 2,425 (of 3,193 total)