Support

Account

Home Forums Search Search Results for 'taxonomy'

Search Results for 'taxonomy'

reply

  • OMG, that works like a charm. Thank you so, so much!!!!
    Just a last question:

    So I do not need these 2 lines

    //	get the current taxonomy term
    	$term = get_queried_object();

    here in the loop-index.php at line 90: https://pastebin.com/nafjw9LQ ?

  • G’day Mate,

    the function get_queried_object is getting the current object. So, on a archive page, the current object is the current taxonomy term. However, on the single, it is the current post. That’s why acf couldn’t return the value unless you tell it to get it from the taxonomy.

    On line 192, where the theme is using get_the_term_list to build the category list. However, if you want to apply custom class to it, you’d need to construct the html output yourself.

    So, you should update that section to look like:

    
    if(!empty($taxonomies))
    {
        foreach($taxonomies as $taxonomy)
        {
            if(!in_array($taxonomy, $excluded_taxonomies))
            {
                // get all the terms in this taxonomy
                $terms = get_the_terms(null, $taxonomy)? : [];
    
                foreach ($terms as $term) {
                    // loop through them, and add the color as style attribute
                    $cats .= sprintf(
                        '<a href="%s" style="color: %s">%s</a>', 
                        get_term_link($term),
                        get_field('color', $term),
                        $term->name
                    );
                }
            }
        }
    }
    

    Cheers

  • Sorry, that should be wp_get_object_terms()' and there is an extra;` probably causing an error in the last bit of code.

    But this is basically what you need to do. To get the field from the term/taxonomy you need to provide ACF with the right $post_id value. See: https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/

  • I’ve needed this as well, so I created a custom field setting which allows for conditional logic based on taxonomy. Give it a try when you get a chance.
    https://github.com/andrejpavlovic/acf-conditional-logic-advanced

    ACF Conditional Logic Advanced

  • I’ve needed this as well, so I created a custom field setting which allows for conditional logic based on taxonomy. Give it a try when you get a chance.
    https://github.com/andrejpavlovic/acf-conditional-logic-advanced

    ACF Conditional Logic Advanced

  • I’ve needed this as well, so I created a custom field setting which allows for conditional logic based on taxonomy. Give it a try when you get a chance.
    https://github.com/andrejpavlovic/acf-conditional-logic-advanced

    ACF Conditional Logic Advanced

  • I’ve needed this as well, so I created a custom field setting which allows for conditional logic based on taxonomy. Give it a try when you get a chance.
    https://github.com/andrejpavlovic/acf-conditional-logic-advanced

    ACF Conditional Logic Advanced

  • I’ve needed this as well, so I created a custom field setting which allows for conditional logic based on taxonomy. Give it a try when you get a chance.
    https://github.com/andrejpavlovic/acf-conditional-logic-advanced

    ACF Conditional Logic Advanced

  • The first thing you need to do is get the term in the taxonomy that the post is in

    
    $terms = get_object_terms($post->ID, 'TAXONOMY SLUG HERE');
    

    this will return an array of terms that the post is in, assuming there is only one

    
    $term = $terms[0];
    

    now you can use this to get the fields from the term

    
    $value = get_field('field on term/taxonomy', 'term_'.$term->term_id;);
    
  • Hi,

    Sorry for not getting back earlier. Following is the way I set up acf on my Store taxonomy

    https://screenpresso.com/=hKDUc

    Following is how I have implemented in Stores taxonomy php file

    https://screenpresso.com/=K6Zwg

    I am also copy-pasting the code here for your perusal

    `<div><?php

    global $post;

    // load all ‘category’ terms for the post
    $terms = get_the_terms($post->ID, ‘stores’);

    // we will use the first term to load ACF data from
    if( !empty($terms) )
    {
    $term = array_pop($terms);

    $custom_field = get_field(‘description’, $term );
    echo $custom_field;
    // do something with $custom_field
    }

    ?></div> `

    The code on “Store” taxonomy is as shown above. The output can be seen here: https://offcoupon.in/store/amazon-coupons/

    Please check the bottom section of the above page. Of course, it is working well for Amazon coupon store but it doesn’t work well on Foodpanda store) (https://offcoupon.in/store/foodpanda-coupons/ where it shows description of another store. This is just one incidence. It happens on almost all pages in “Category” taxonomy.

  • Hi @jstas

    The instructions on this page could shed some light on the required code: https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/

    Please take a look.

  • Hi @nathanaelphilip,

    Thank for reply.

    I know this function but it’s just create a new term if the term not exist.

    Now i would like to make the selected value into the acf field taxonomy.

    I see it’s a Select2.

    Thanks in advance.

  • Hi @ricky709

    Can you show us how you have the ACF fields set up, and how you’re pulling the info in your template?

    If you haven’t, I would recommend reading over the get_field documentation here – especially the part about pulling data for a term:

    info about taxonmies => https://www.advancedcustomfields.com/resources/taxonomy/
    help with debugging => https://www.advancedcustomfields.com/resources/debug/
    search for other articles => https://www.advancedcustomfields.com/resources/

    Phil

  • Yeah im trying to pull this from a taxonomy term, and it is returning results. But its just pulling the first row of the repeater.

    So is the error in the Repeater section or the Post Object section?

    If i remove the setup_postdata($post); line, it returns the correct number of rows, just without any data inside of them.

  • @miked89 & @beee

    i thought it needed a $post_id, but you’re fetching fields from a term not a post. You can find your solution here: https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/

    Basically you’re not passing the proper value to the second parameter.

  • You can filter those out this way: https://www.advancedcustomfields.com/resources/acf-fields-taxonomy-wp_list_categories/

    So the next thing to do is to listen for a change on the checkbox and then show the div you just hid. Then you’ll either need to fetch the children of those selected, or, if possible, hide the checkboxes.

    If there’s a way to customize the HTML that ACF spits out on that form, then you could add a class or data attribute with the id of its parent (this is on the County stuff).

    I don’t see a filter for adjusting that HTML, but you could try formatting it via this: https://www.advancedcustomfields.com/resources/acf-render_field/

    Basically you’d hijack the HTML it outputs with your own.

  • Hi Phil,
    Thanks for the help, a little unsure how to implement the solution though.

    Would it be saving the Tag ID into the variable as the ACF Repeater is on a custom taxonomy page?

  • Hey shanekins,

    You seem to be pretty close with this.. assuming that the dropdown you have created is returning the term ID, all you need to do is use the built in WordPress function ‘get_term’ to get the taxonomy’s name:

    
    
    function my_save_post( $post_id ) {
    
        // Pull the Term ID from the form:
        $term_id = $_POST['acf']['field_59940ffa4a644'];
    
        // Now get the WordPress term Object:
        $term = get_term( $term_id );
    
        // Check to see that a term is returned successfully
        if ( ! empty( $term && ! is_wp_error( $term ) ) )
        {
    
            // Now you can get the term name for your title
            $title = $term->name;
    
            $new_post = array(
                'ID'           => $post_id,
                'post_status' => 'publish',
                'post_title' => $title,
                'post_type' => 'points'
            );
    
            remove_action('acf/save_post', 'my_save_post', 20);
            wp_update_post( $new_post );
            add_action('acf/save_post', 'my_save_post', 20);
        }
    
    }
    
    add_action('acf/save_post', 'my_save_post', 20);
    
  • My super-power is getting ahead of myself… I’ve been found out. 🙂

    Here you go: two fields created and both are that same taxonomy. http://recordit.co/TNCBAXw484
    So far, so good?

  • Hey Hey,

    1. No, both will be taxonomy options – since you’re using ACF forms to display the form, it needs to know what data to expect. So you’ll basically have 2 of the same fields, but one is for the States and one is for the Counties. Once your user selects the State(s), we’ll use that to populate the data in the Counties <select>, but I wanted you to get comfortable with the first part first.

    2. you’re getting ahead of yourself – once you accomplish what I laid out in the previous post, we’ll move on to Part 2.

    Phil

  • You’ve got it. (and THANK YOU again!!!) I’ll start working immediately. To be sure I’m starting out on the right track I have 2 questions:

    1. I’m assuming that neither the state nor the counties fields I’ll be creating will be set to taxonomies, but just checkbox fields holding the options. Is that right? (adding a snap of the taxonomy screen in case it’s helpful to see that setup)

    2. Assuming I’m on the right track, I’m wondering if I should maybe create a Counties box for each state so the values remain separate and easy to distinguish? (checking WA will open a WA-Counties box, for example) Yes, there will be 50 counties fields, but they’ll each have the values just for that state. ?

  • Hello,

    I have the same problem but how would I make it work with the Visual Composer element ? I am trying to display the Taxonomy names

  • I came across this while trying to solve a similar problem. In my case, I have a Taxonomy field as radio buttons that I would like to style more like the True/False UI.

    I thought it would be doable via some admin CSS, but the markup is such that there’s no way to target a checked input’s label. (The common way to do this is via adjacent selectors in CSS, but ACF outputs the radio button input as a child of its label, not a sibling, unfortunately.)

    It seems like this would be a logical change to the markup in ACF so that we would have more flexibility to “roll our own.” Unless I’m missing a possibility here?

  • Can you explain more what you mean by this statement?

    “7) I then added a ‘course_categories’ selection to the ‘courses’ I had created.”

    What do you mean by ‘selection’? Radio buttons? A Select drop-down?

    Just off the top of my head, if you are adding a taxonomy to your custom post type, you don’t need to add an additional ACF selection field, especially with the same slug/name. This will create unexpected results.

    Once you’ve created the custom taxonomy, you can use the built-in WordPress support for taxonomies.

    In any case, you have two options so pick one but you shouldn’t really use both:

    1) If you want to use your custom taxonomy, make sure your cpt supports the custom taxonomy and vice-versa that your custom taxonomy is attached to your custom post type.

    Then, make sure your edit screen for your custom post type has your taxonomy box checked in ‘Screen Options’. It should look just like the category box for regular Posts.

    Select your taxonomies for your custom post type posts using that box (no ACF select field necessary).

    — OR —

    2) Use an ACF select field (either Select or Checkbox) and then you can query posts by that field (scroll down to Examples): https://www.advancedcustomfields.com/resources/query-posts-custom-fields/

    Thus, you should either use your custom taxonomy or an ACF field but not both – you are just re-selecting something that is already there.

    All that said, there could be uses for grabbing your taxonomies in ACF but make sure that your ACF fields do not have the same slugs as your custom taxonomy.

  • You have the field set to only return the Term ID. Doing this assumes that you’re going to do all the work of getting that name of each term yourself, or whatever else you want to do with that ID.

    If you don’t want to code this yourself then you should be returning Term Object https://www.advancedcustomfields.com/resources/taxonomy/

Viewing 25 results - 1,626 through 1,650 (of 3,193 total)