Support

Account

Home Forums Search Search Results for 'taxonomy'

Search Results for 'taxonomy'

reply

  • First you would need to figure out how to change the output of the link wherever WC is outputting it. Then you’d need to alter the WP rewrite rules for your site, especially since you are talking about altering a taxonomy term url. All could be possible with a large amount of work.

    Alternately, you could create an acf/save_post filter, see if what is being saved is a term in your taxonomy and then alter the term slug every time that the term is saved. Also a possible solution and more likely that the first one. Still a little complicated and I don’t know the exact details of getting it done.

  • I would say that you’ll need to go about setting the default value differently in this case. You’re using a custom taxonomy, so that should make things a bit less difficult since your not dealing with “Uncategorized”

    Rather than using acf/load_field in this case you should use acf/load_value https://www.advancedcustomfields.com/resources/acfload_value/ with a priority > 10

    Going to be honest, I’m not exactly sure what needs to be done, this is a bit of a guess.

    
    add_filter('acf/load_value/key=field_58086a9b13be5', 'kiteboat_set_tax_default', 20, 3);
    
    function kiteboat_set_tax_default( $value, $post_id, $field ) {
    	if ($value === false && get_post_status($post_id) == 'auto-draft') {
    		$value = 304;
    	}
      return $value;
    }
    
  • Is the default value filterable?

    I’ve seen this post on filtering default tax field for front end editor, but the filter’s not working for me in the basic back end admin.

  • You need to add an event to a trigger on the field. For the standard WP category box you need to add an action when something there is changed. For an ACF taxonomy field you need to add an action to the change event of that field. Take a look at the jQuery docs for .on(), .bind(), .click(), etc. There are probably dozens of ways this can be done but really nothing to do with ACF.

    As far as making a specific tab active, all you really need to do is trigger the click event for that tab in the action you add to the other element. For example, if I have an acf field group with the group key of group_586cf71a7742c and a tab with a field key of field_586d38c5329b5

    
    $('#acf-group_586cf71a7742c .acf-tab-wrap [data-key="field_586d38c5329b5"]').trigger('click');
    
  • I don’t know of the OP found a solution. This question was asked a long time ago.

    I would use select fields and not taxonomy fields. For the first field I would dynamically generate the values of the “parent” category form the information here https://www.advancedcustomfields.com/resources/dynamically-populate-a-select-fields-choices/

    For the child category I would use ajax to populate the select field. I have created an example of doing this here https://github.com/Hube2/acf-dynamic-ajax-select-example/tree/master/dynamic-select-example. This example uses posts in a post type, but the principle is the same.

    You would also need to create an acf/save_post filter https://www.advancedcustomfields.com/resources/acf-save_post/ if you want to update the post categories https://codex.wordpress.org/Function_Reference/wp_set_post_terms since you wouldn’t be using a taxonomy field that would do this automatically.

  • I found this helping to select parent categories

    function my_taxonomy_query( $args, $field, $post_id ) {
        // modify args
        $args['parent'] = 0;
        // return
        return $args;
    }
    
    add_filter('acf/fields/taxonomy/query', 'my_taxonomy_query', 10, 3);

    Image example: http://prntscr.com/e5i7a7

    I created another custom field to select the child category, but how would it work?

  • I asked about the filter because if the data is migrated in some what that does not preserver the Term and Taxonomy/Term ID values then it could be that they are different on the two sites and this would cause an issue.

    I cannot reproduce this issue when testing, so I haven’t got a clue what it could be. My best suggestion at this point would be to open a new support ticket https://support.advancedcustomfields.com/new-ticket/

  • _post_category is not one of the special fields defined by ACF in acf_form(), only _post_title and _post_content.

    If this is from a taxonomy field, set the field to save and load terms.

  • Oh yesssss.

    Sorry I didn’t realize that product types were a taxonomy of the WooCommerce products.

    Big thx for this.

    Gilles

  • @yumyo I don’t think you are experiencing a JS problem. With that many categories on the site try unchecking Taxonomy in the filters. In order to use this filter ACF loads and sorts all of the taxonomy/terms for the site.

  • For what I can see so far, it is closely related to the filters part of the field settings (Filter by Post Types, Filter by Taxonomy, Filters) which specifically hangs for a couple of seconds before loading, even if just a relationship field is present inside the Group.

    A specific characteristic of the website I am working on, is the high number of Categories, 309 at the moment. Could this be the real cause of the issue?

    Every kind of field that loads those filters seems to add delay up till making the page totally unstable. Two relationships and 4 Post Object are enough to trigger the Chrome script warning.

    I really need to find at least a temporary workaround as the site is in production and changing data structure is clearly out of question. It is possible to edit the fields with JS disabled or it MUST be on?

  • So I actually went with $wpdb because I can combine that with some additional requirements I had. Here’s the query I ended up with:

    
       $category_slug = $_GET["category"];
    
       if($category_slug) {
         $category_query = $wpdb->prepare("AND wp_terms.slug = %s", $category_slug);
       } else {
         $category_query = "";
       }
    
        $event_dates_query = <<<EOD
        SELECT  event_dates.*, $wpdb->terms.name AS category_name
          FROM  $wpdb->posts AS event_dates
          INNER JOIN $wpdb->postmeta AS acf_event
            ON acf_event.meta_key = 'event'
              AND acf_event.post_id = event_dates.ID
          INNER JOIN $wpdb->postmeta AS acf_date
            ON acf_date.meta_key = 'date'
              AND acf_date.post_id = event_dates.ID
          INNER JOIN $wpdb->posts AS events
            ON events.ID = acf_event.meta_value
          INNER JOIN $wpdb->term_relationships
            ON $wpdb->term_relationships.object_id = events.ID
          INNER JOIN $wpdb->term_taxonomy
            ON $wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id
          INNER JOIN $wpdb->terms
            ON $wpdb->term_taxonomy.term_id = wp_terms.term_id
          WHERE (acf_date.meta_value >= %s
                 AND acf_date.meta_value < %s)
                 AND event_dates.post_type = 'event_date'
                 AND event_dates.post_status = 'publish'
                 $category_query
          GROUP BY event_dates.ID
          ORDER BY acf_date.meta_value ASC;
    EOD;
    
      $event_dates = $wpdb->get_results(
        $wpdb->prepare($event_dates_query,
          $first_day_of_month,
          $last_day_of_month));
    
    

    Besides joining various term-taxonomy-meta-tables I also filter the EventDates by their date, so I can paginate them by month.

    So there’s quiet an ugly query sitting in my template now, but I think in terms of performance and lines of (php) code written that’s the best I can hope for here.

    Based on this query I was also able to build a fulltext search where I query for attributes and meta-keys of Events and get back their related EventDates quiet easily, so thats nice too.

  • You are right, there isn’t any way to do this using WP_Query. Doing this on the event date archive is going to be extremely complicated. Well, doing it anywhere is going to be complicated because event category is not really related to the event date except through the event.

    Doing this with just the basic function that WP gives us you would need to… and I’m not sure about this

    1) Get all the even categories
    2) Get all the events in each category
    3) Somehow sort them by the event date and there isn’t any way to sort posts based on a field in another post

    What you need to be able to do is one WP_query on the events. The best way to accomplish this is to store all of the information you need to query as part of the event.

    I’ve posted several replies here about making repeaters easier to search and this is the same basic principle. You take information that you want and copy it to where it will help you the most.

    
    add_action('acf/save_post', 'make_events_filterable');
    function make_events_filterable($post_id) {
      if (get_post_type($post_id) != 'event') {
        // return;
      }
      // set up two fields to store the information
      // these need to have unique names that are different than the acf field names
      $category_field = 'event_category';
      $date_field = 'event_date';
      // delete anything that's currently stored in these two fields
      // to avoid creating duplicates
      delete_post_meta($post_id, $category_field);
      delete_post_meta($post_id, $date_field);
    
      // This is the complicated bit. You need to get the value the
      // category taxonomy field
      // and the date relationship field
      // loop through them, get the value you want to store from those locations
      // and then update the new post meta field with those values
      
          // start loop for a field
          // get value for the field
          add_post_meta($post_id, $field_name, $value, false);
          // false at the end means it can have multiple values
      
    }
    

    Now you can use these fields in WP order by clauses in the meta query to order your event posts by category and date https://make.wordpress.org/core/2015/03/30/query-improvements-in-wp-4-2-orderby-and-meta_query/

    With them in the right order you can loop through them and output new category and date headings when they change.

    Hope some of this helps.

  • You’ll need to look at how to get the term for the template of in the code you’re modifying then. But this is the right syntax to use

    
    $grade = get_field('grade', $taxonomy . '_' . $term_id);
    
  • $queried_object = get_queried_object();
    	        $taxonomy = $queried_object->taxonomy;
    			$term_id = $queried_object->term_id;  
    
    			$grade = get_field('grade', $queried_object);
    			$grade = get_field('grade', $taxonomy . '_' . $term_id);
    
    			var_dump($grade);

    The var_dump shows “NULL NULL NULL”

  • you need the term ID

    
    $queried_object = get_queried_object();
    
    // ACF5 >= 5.5
    get_field('field_name', 'term_'.$queried_object->term_id');
    
    // ACF < 5.5
    // get_field('field_name', $queried_object->taxonomy.'_'.$queried_object->term_id');
    
  • 
    <?php 
      
      
      // step 1 add a location rule type
      add_filter('acf/location/rule_types', 'acf_wc_product_type_rule_type');
      function acf_wc_product_type_rule_type($choices) {
        // first add the "Product" Category if it does not exist
        // this will be a place to put all custom rules assocaited with woocommerce
        // the reason for checking to see if it exists or not first
        // is just in case another custom rule is added
        if (!isset($choices['Product'])) {
          $choices['Product'] = array();
        }
        // now add the 'Category' rule to it
        if (!isset($choices['Product']['product_cat'])) {
          // product_cat is the taxonomy name for woocommerce products
          $choices['Product']['product_cat_term'] = 'Product Category Term';
        }
        return $choices;
      }
      
      // step 2 skip custom rule operators, not needed
      
      
      // step 3 add custom rule values
      add_filter('acf/location/rule_values/product_cat_term', 'acf_wc_product_type_rule_values');
      function acf_wc_product_type_rule_values($choices) {
        // basically we need to get an list of all product categories
        // and put the into an array for choices
        $args = array(
          'taxonomy' => 'product_cat',
          'hide_empty' => false
        );
        $terms = get_terms($args);
        foreach ($terms as $term) {
          $choices[$term->term_id] = $term->name;
        }
        return $choices;
      }
      
      // step 4, rule match
      add_filter('acf/location/rule_match/product_cat_term', 'acf_wc_product_type_rule_match', 10, 3);
      function acf_wc_product_type_rule_match($match, $rule, $options) {
        if (!isset($_GET['tag_ID'])) {
          // tag id is not set
          return $match;
        }
        if ($rule['operator'] == '==') {
          $match = ($rule['value'] == $_GET['tag_ID']);
        } else {
          $match = !($rule['value'] == $_GET['tag_ID']);
        }
        return $match;
      }
      
      
    ?>
    
  • /wp-admin/term.php?taxonomy=product_cat&tag_ID=15&post_type=product&wp_http_referer=%2Fdemo%2Fchla%2Fwp-admin%2Fedit-tags.php%3Ftaxonomy%3Dproduct_cat%26post_type%3Dproduct

    /wp-admin/term.php?taxonomy=product_cat&tag_ID=16&post_type=product&wp_http_referer=%2Fdemo%2Fchla%2Fwp-admin%2Fedit-tags.php%3Ftaxonomy%3Dproduct_cat%26post_type%3Dproduct

  • Hi John,

    Thank you for your replies. Despite several tests, i can’t do it. Have you a concrete example of the second method ?

    Also, I have tweaked something to arrive where i want but the problem is that if the choice is not checked its value appears anyway even if there are no posts related. The result is :

    DATE 1 (taxonomy)

    Location 1 (taxonomy)
    Film A
    Film B

    Location 2
    Film B
    Film C

    Location 3

    If Location 3 is empty, i don’t want to display it…

    I think your method is best than mine 😉

        <?php // CHAMPS LIEUX
    
        $jours_key = "field_5886014c7f9f1";
        $jours = get_field_object($jours_key);
    
        foreach($jours['choices'] as $k => $v) : 
    
        $lieux_key = "field_5880dc1d1f784";
        $lieux = get_field_object($lieux_key); 
    
        ?>
    
        <h3><?php echo $v; ?></h3>
    
        <?php foreach($lieux['choices'] as $cle => $valeur) :
    
        $args = array(
            'post_type'     => 'film',
            'meta_query'    => array(
                'relation'      => 'AND',
                array(
                    'key'       => 'seances_%_jour2',
                    'compare'   => 'LIKE',
                    'value'     => $k,
                )
            )
        );
        $the_query = new WP_Query( $args ); ?> 
    
        <h3 style="color:#ccc"><?php echo $valeur; ?></h3>
      
        <?php if($the_query->have_posts()) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    
                <?php if( have_rows('seances') ): while( have_rows('seances') ): the_row(); 
                    $date = get_sub_field('jour2');
                    $lieux = get_sub_field('lieu');
                    $horaire = get_sub_field('horaire'); ?>
    
                    <?php if ($date['label'] == $v && $lieux['label'] == $valeur) : ?>
                        <p><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></p>
                        <p><?php echo $horaire; ?></p>
                    <?php endif; ?>
    
                <?php endwhile; endif; ?>
    
        <?php endwhile; endif;  wp_reset_postdata(); ?>
    
        <?php endforeach; ?>
        <?php endforeach; ?>
  • Duh, my fault. That will only let the field group appear on posts in that category. There isn’t a location rule that exists for adding field groups to specific terms (term editor page), only for all of the terms in a taxonomy.

    You need a custom location rule for this https://www.advancedcustomfields.com/resources/custom-location-rules/. This is a fairly common one, but I don’t have an example. I’m sure that somewhere on this forum there is an example for this location rule but I can’t seem to find it right now.

  • Hi, I have a question if you can spare a few moments: a couple of years ago I created a page builder using flexible and repeater fields – while I kept things very simple (around 5-6 layouts with a couple of fields each), I had no issues. Alas, once I started adding complexity (doubled the layouts, each with 15-20ish fields) saving a post started taking 10-20 seconds (or even more), while the overall browser performance rendered the interface barely usable (very low framerate/browser begging me to kill it).

    Given this issue, I went for a different approach:

    • For post & pages I used a “lite” page builder with very few fields.
    • For the front-page (which usually has more content and diversity), i created a custom post type called “blocks” and loaded field-groups depending on the taxonomy (e.g. “block-gallery”, “block-map”, etc).

    Now, what I wanted to ask you is: while I’m pretty sure ACF performance has improved since 2 years ago, I can’t help but wonder – do you think there’s a chance you may end up hitting a wall where too many layouts & fields may hinder/ruin the users experience (specifically on mobile devices or old computers)? Do you have a different approach in mind?

  • Just to follow-up after a bit of extra digging, I need to keep the term as returning ID, as opposed to object to avoid conflicts elsewhere.

    So in essence, I’m looking for a way to pull in the taxonomy value (name) and display that instead of the ID.

  • Hi,
    in fact , the problem was the $oeuvre variable, for it is an array
    i had to write :
    $term_taxonomy_ids = wp_set_object_terms( $oeuvre->ID, $term_id, ‘statut_oeuvre’);
    in steadof
    $term_taxonomy_ids = wp_set_object_terms( $oeuvre, $term_id, ‘statut_oeuvre’);
    Thanks for help
    Fred

Viewing 25 results - 1,851 through 1,875 (of 3,194 total)