Support

Account

Home Forums Search Search Results for 'taxonomy'

Search Results for 'taxonomy'

reply

  • There is nothing easy or simple.

    Taxonomy => company
    Taxonomy => company-type

    Where each company has a selected company type

    To do this you would need to get all of the terms in company using get terms. Then you would need to loop over the entire set and use get_field() to get the company type. You can’t use get_terms() because in WP terms cannot have terms. Using this method you can assemble your own subset of companies that have a specific company type.

    Going back to the beginning I would probably have made company a custom post type with company type being the taxonomy.

  • Thank you! Your answer was a part of my solution. For anyone else who stumbles upon this thread and wants to do something similar, here’s my code that works in my project.

        <!-- start REPEATING THIS CONTENT - ICON/class card wrapper -->
        <?php if(have_rows('category_preview_offering')): ?>
    
        <div class="class-card-wrapper">
    
          <?php while(have_rows('category_preview_offering')): the_row();
            //Vars
            $image = get_sub_field('image');
            $term = get_sub_field('category_name');
            $taxonomy = 'category';
            $term_link = get_category_link($term[0]->term_id);
    
            if($term): ?>
    
            <div>
            <!-- start card one -->
            <!--  <a href="/index.php?cat=4"> -->
            <a href="<?php echo $term_link; ?>">
                <div class="icon_individual_card grow">
    
                    <img src="<?php echo $image['url']; ?>" alt="<?php echo $image['alt']; ?>">
    
                    <p class="icon_text_color blog_category_title"><?php echo $term[0]->name; ?></p>
                </div>
            </a>
          <?php endif; ?>
          </div>
            <!-- end card one -->
          <?php endwhile; ?>
    </div>
    <?php endif; ?>
    <!-- end ICON/class card wrapper -->
    </section>
    
    <!-- end BLOG CATEGORIES 3 ICON/class cards -->
  • This $taxonomy = 'category_name'; appears to be the name of the field and it should be the name of the taxonomy. If you’re using the built in WP category taxonomy it should be $taxonomy = 'category';

  • Hi

    I’m using elementor and Ocean WP theme.

    I have created a new custom field called ‘category image’ and applied it to a new taxonomy I made using CPT UI called ‘Success Story Categories’. The intention being that when I click on a category, I want it to display the archive page for that category, plus a category image.
    It works fine in Elementor edit mode and the dynamic field changes depending on which category is shown. But when I look at it from the users front end, the image is not displaying. It will only show a fallback image.

    Is this the same issue as Jennifer and Arthur do you think? Or should I start a new thread?

  • What you’re getting indicates that a post is being queried and not a term. This is why you’re getting nothing.

    get_queried_object() will only return a term in a taxonomy or term template, not in a template that displays a post. You will need to use some other method to get the term associated with the post. I would suggest looking into this https://codex.wordpress.org/Function_Reference/wp_get_post_terms

  • Alright, I tried what you suggested and here is the output I got:

    WP_Post Object
    (
        [ID] => 2246
        [post_author] => 1
        [post_date] => 2018-11-19 03:43:12
        [post_date_gmt] => 2018-11-19 03:43:12
        [post_content] => 
    
    [xyz-ips snippet="Taxonomy"]
        [post_title] => ISS Explorer
        [post_excerpt] => 
        [post_status] => publish
        [comment_status] => closed
        [ping_status] => closed
        [post_password] => 
        [post_name] => iss-explorer
        [to_ping] => 
        [pinged] => 
        [post_modified] => 2018-11-20 05:52:17
        [post_modified_gmt] => 2018-11-20 05:52:17
        [post_content_filtered] => 
        [post_parent] => 0
        [guid] => http://localhost/?post_type=webworks&p=2246
        [menu_order] => 0
        [post_type] => webworks
        [post_mime_type] => 
        [comment_count] => 0
        [filter] => raw
    )
    
        [post_title] => ISS Explorer
        [post_excerpt] => 
        [post_status] => publish
        [comment_status] => closed
        [ping_status] => closed
        [post_password] => 
        [post_name] => iss-explorer
        [to_ping] => 
        [pinged] => 
        [post_modified] => 2018-11-20 05:52:17
        [post_modified_gmt] => 2018-11-20 05:52:17
        [post_content_filtered] => 
        [post_parent] => 0
        [guid] => http://localhost/?post_type=webworks&p=2246
        [menu_order] => 0
        [post_type] => webworks
        [post_mime_type] => 
        [comment_count] => 0
        [filter] => raw
    )

    I’m confused, but I think you might be right, for some reason it’s not showing any tags that are attached to the post. Correct me if I’m wrong.

  • Just tried both and it still results in an empty output:

    <?php
    $term = get_queried_object();
    $image = get_field('taxonomy_images',  'term_' . $term->term_id);
    
    ?>
    
    <img src="<?php echo $image ?>"/>
  • 
    $term = get_queried_object();
    
    // USE
    $image = get_field('taxonomy_images',  'term_' . $term->term_id);
    
    // OR
    $image = get_field('taxonomy_images',  $term);
    
  • Hmm, perhaps I am approaching this from the wrong angle then.

    Remember those categories I mentioned? They have their own page on a site, about the category. And I gave an example of 5 but there’s really like a couple of dozen categories, with a page for each one.
    The way the current website is set up is that the testimonials are manually entered for each page. My thought was that, in a redesign, I could set up a Testimonials custom post type, give each a category, and then just use a page template in conjunction with ACF that would have a section at the bottom saying, “Pull in the testimonials that were selected on this page.” It also would be future-proof, in a way, if I had it set up to display the most recent 3, too; people wouldn’t have to manually go into the page and edit it as they do now.

    But if I have to create a taxonomy template for each of the dozen categories, and then additionally possibly change the URL structuring for them to get pulled in and display properly, that might not be worth all the effort.
    It’s also possible I’m just not following the suggestion, but my thoughts had originally been that I could simply edit a page template — even if it was THE page.php template, with a “if testimonials exist, display them from the selected category here” setup (with subsequent styling). But if making a several dozen templates to correspond to each selection is necessary to proceed, I don’t know if that’s the route to go for efficiency.

  • If you’re using a page template to show testimonials then there is not automatic filtering of categories. In order to provide a select field or some other mechanism on this page you would need to build the page to filter by some type of url query string value. See the “Dynamic $_GET parameters” section of this page https://www.advancedcustomfields.com/resources/query-posts-custom-fields/ Without doing this there is nothing passed to your page template that will let you filter the posts.

    If you use a custom taxonomy, for example let’s say you name it “testimonial-category” and you create a template for this taxonomy as I mentioned then WP will use this template files and automatically filter the testimonials for you and you simply need to link to that page. For example http://yoursite.com/tesimonial-category/doors/. This template file would work the same as the standard archives.php, category.php or tag.php file.

  • Thanks, John.

    The first part of what you said helped out a lot. I was able to set up a Field Group so that a dropdown appeared on a new Page and one of the Testimonial categories would be able to be selected.

    I’m a bit confused on the second part, however. I had created a new page template (and used it in my test page) so I could tinker with the correct syntax, but I can’t get it to appear. I’d think the syntax would be something like “if a testimonial category is chosen (ie not blank), display it” but it’s not really working out. I also tried using the Basic Display (single value) example syntax from https://www.advancedcustomfields.com/resources/taxonomy/ (even changing the ‘taxonomy field name’ to what I used in my field group), but nothing displays inside the H2 or p, so I know I’m doing something wrong.

    Let’s say my Testimonials custom post type has the following categories: Yardwork, Driveways, Windows, Doors, and Roofs. If I was trying to write the code block in a page template, what would the syntax for such a thing be?

    Or, if I’m making a template (using a slug as you say), can you give me an example of the code block syntax that would go in the template file as you referred to it?

  • There are 2 thing you need to do here. The first this would be to create the ACF taxonomy field and set it to load and set terms.

    The second thing has to do with showing the testimonials in each category. This is actually a core WP thing. You just need to create a template for the taxonomy. This works best when you create a custom taxonomy so that your testimonials do not get mixed into the standard post categories and visa-versa. https://codex.wordpress.org/Function_Reference/register_taxonomy. Then you create a template file named “taxonomy-YOUR-TAX-SLUG-HERE.php”

  • What @vipstephan says sounds like what you want. You need a custom post type and maybe a custom taxonomy or 2. I don’t think what you’re trying to do can be achieved with ACF alone.

  • That information would have been helpful. You need to supply the correct value so ACF know where to get the value from https://www.advancedcustomfields.com/resources/adding-fields-taxonomy-term/

  • Hi,
    same issue here:
    i got a group of ACF with one image and one color.
    This group applies to Pages, a Custom Post, and a Custom Taxonomy.
    Custom Post and Custom Taxonomy are created using CPT UI.

    The weird thing is that my ACF group is working fine on Pages and on Custom Posts,
    but with Custom Taxonomy, the fields appears but are empty (do not recall last saved values) and won’t save new values.

    Thanks for your help…

  • Apologies, I didn’t explain that very clearly. We were filtering a taxonomy field by a term. The term slug was changed, after which posts tagged by that term could no longer be picked. My initial thought was that if it was using the term ID, surely it wouldn’t falter when trying to filter posts, even if the slug had been changed?

  • I try to put this code in taxonomy-models.php, but nothing happens.

    prices – repeater field
    model_term – taxonomy field
    price_term, time_term – text fields

    <?php 
    
    if (have_rows('prices')) {
      while (have_rows('prices')) {
        the_row();
    
    $queried_object = get_queried_object();
    $term_id = $queried_object->name;
    
        if (get_sub_field('model_term') == $term_id) {
          the_sub_field('price_term');
          the_sub_field('time_term');
        }
      }
    }
    
     ?>
  • The only “ID” that a taxonomy has in WP is the slug (or taxonomy name). Taxonomies are not stored in the DB and do not have any other ID value. You cannot change the slug without effecting everything that depends on it. The list of things that this would effect is quite large and I’m sure that if I tried to list them all that I’d miss a few.

    If the goal of doing this was to change the slug shown in the URL string then what should have been changed is the rewrite slug https://codex.wordpress.org/Function_Reference/register_taxonomy

  • Ah, until your last comment it was not clear that this was on the “Add Term” page.

    At least that’s where I’m seeing this bug. For other users in this thread it seems to happen on other pages, too (but not for me).

    I suspect this has something to do with WP submitting and reloading the fields on the page through AJAX and scripts needed for the wysiwyg field are not loaded properly, but I don’t know.

    I’m pretty sure there’s no problem with WP core code here, because a standard taxonomy does not have a WYSIWYG-field, so there’s no need to handle such scripts.

    You should submit a but report on this here

    Thanks, will do.

  • Thanks @hube2! I think it was one of your previous replies that helped me solve my issue prior to you responding to my post. Here’s the full final code for anyone else having issues. Also, the image field in ACF settings is set to Image ID. I have this set to take advantage of WordPress serving up responsive images.

              <div class="inner-row large-up-3 small-up-2">
                <?php
                $taxonomy = 'jobpost_category';
                $terms = get_terms($taxonomy, $args = array(
                  'hide_empty' => false,
                ));
    
                ?>
    
                <?php foreach( $terms as $term ) :
                $catIMG = get_field('job_cat_image', 'jobpost_category_' . $term->term_id);
                ?>
    
                <a class="image-nav-block" id="post-<?php the_ID(); ?>" href="<?php echo get_term_link($term->slug, $taxonomy); ?>">
                  <div class="nav-block-overlay">
                    <div class="title-overlay">
                      <?php echo $term->name; ?>
                    </div>
                    <?php echo wp_get_attachment_image($catIMG, 'medium'); ?>
                  </div>
                </a>
    
                <?php endforeach;?>
    
              </div>
  • I agree. I’m as of now taking a shot at it. I need to add a few models to the taxonomy templates documentation. Particularly in the taxonomy templates layouts area. I’d get a kick out of the chance to include a case for the taxnomy.html and terms templates.html. Regardless i need more clarification how to do that.

    support.advancedcustomfields
    achieve essays

  • Deactivated all other plugins and even switched to the standard WP theme Twenty Sixteen, problem still exists.

    Here are the steps to reproduce the error:

    1. Create new field group
    2. Create new field, type WYSIWYG-Editor. Leave all other field options on default
    3. Create rule: Taxonomy is Category
    4. Successfully add a new category term in Posts -> Category
    5. While trying to re-init TinyMCE for the WYSIWYG field, JS error is thrown

    If you set the “delay” option for the WYSIWYG-field to “yes”, the error is not thrown after a term was added, but when you click on the field to init TinyMCE.

  • Hi Federico!

    I was on a holiday so late reply here.

    Can you be more specific, do you have example code?

    Anyway, the code I used in my functions.php was:

    /**
     * Hooks the WP cpt_post_types filter 
     *
     * @param array $post_types An array of post type names that the templates be used by
     * @return array The array of post type names that the templates be used by
     **/
    function my_cpt_post_types( $post_types ) {
        $post_types[] = 'beugel';
        $post_types[] = 'kingweg';
        $post_types[] = 'groep_8';
        return $post_types;
    }
    add_filter( 'cpt_post_types', 'my_cpt_post_types' );
    
    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', 10, 3);
  • I tried both leanda version and Florian version – none worked. I got no error, just category is still visible in frontend form. What I try to achieve: exclude category with ID 158 from being visible in frontend form, slug of this field is “tematyka”. So my code is:

    <?php
    add_filter(‘acf/fields/taxonomy/wp_list_categories/name=tematyka’, ‘my_taxonomy_args’, 10, 2);

    function my_taxonomy_args( $args, $field )
    {
    $args[‘exclude’] = array(158); //the IDs of the excluded terms
    return $args;
    }
    ?>

    I tried also without name, to exclude this category from all fields and forms (though I have only one form):

    <?php
    add_filter(‘acf/fields/taxonomy/wp_list_categories’, ‘my_taxonomy_args’, 10, 2);

    function my_taxonomy_args( $args, $field )
    {
    $args[‘exclude’] = array(158); //the IDs of the excluded terms
    return $args;
    }
    ?>

    None worked. What did I wrong?

  • Hi,

    I would appreciate help. I tried above solution with small modyfication – I want to exclude one category from front-end form, category ID is 158, acf field slug – tematyka
    I put it on the functions.php of my theme:

    function blokada_kategorii( $args, $field, $post_id ) {
    $args[‘exclude’] = ‘158’;
    return $args;

    }

    add_filter(‘acf/fields/taxonomy/query/name=tematyka’, ‘blokada_kategorii’, 10, 3);

    And I get error:
    Parse error: syntax error, unexpected ‘=’, expecting ‘,’ or ‘)’ in [shortened]/functions.php on line 202
    Line 202 is where add_filter… is

    What I did wrong? Or is any other method to exclude one category from the field?

Viewing 25 results - 1,451 through 1,475 (of 3,194 total)