Support

Account

Home Forums Search Search Results for 'taxonomy'

Search Results for 'taxonomy'

topic

  • Helping

    filter field taxonomy

    Hi, I’m trying to add a simple category filter to add to an ACF field. I would need to filter the search results, restricting it to only two specific categories for selection. I use this code in functions.php

    thanks

    
    add_filter('acf/fields/taxonomy/query/name={$cat_f}', 'my_acf_fields_taxonomy_query', 10, 3); //
    function my_acf_fields_taxonomy_query( $args, $field, $post_id ) {
    // Show 2 terms per AJAX call.
    $args['name'] = 'cat1, cat2';
    return $args;
    }
    
  • Unread

    Automatic check when new terms added to the post

    Hi. I’m using this Taxonomy Terms and connected it to the custom post where the Tags (as terms) and the Document Folder (activating the terms to front-end) are both selections to User Profile. Is there a simple hook that aside from the Toggle All, it will automatically “check” the checkbox when adding new terms from the custom post?

    in my screenshot here, as you can see i have my term “test broadway 2” in my screenshot 1, but in my screenshot folders list, it is unchecked. since we have 500 users in our admin, we will manually check that field each of the user (referring to screenshot Folders List – User Profile) and it is so hassle.

  • Unread

    Add ACF field in ajax_add_term pop-up

    Here’s the translation and correction:

    As requested by user @Zek, I’m trying to find a way to display custom fields of a taxonomy in the pop-up that opens when creating a new term from the post edit screen.

    Zek suggests a solution that overrides the ‘ajax_add_term’ function within the file advanced-custom-fields-pro/includes/fields/class-acf-field-taxonomy.php line 856.
    Is there an alternative solution to avoid touching the plugin code and work from my theme’s function?

    Original Topic:
    https://support.advancedcustomfields.com/forums/topic/add-field-to-add_term-lightbox-in-taxonomy-field/

    I’ve attached a screenshot of the pop-up for clarity.

  • Solved

    Trading Cards, taxonomy/hierarchy Help

    The image is basically what I’m trying to achieve with ACF & Elementor. The hierarchy and putting this together has been giving me trouble for the past 4 days now so I’m posting this for help.

    My Logic right now: The Star system is the “top or highest” level for a custom post (Card)
    Example 1) Footwear>Sandals>Laces
    Example 2) Computer Hardware>Computer Parts>Motherboard>*Options: FormFactor | Chipset | Memory Slot | PCI | Brand | RAID| etc….

    Are Footwear & Computer Hardware(Parent Category) The same as the 3,4,5 stars logic?

    1) Is The Star system 3,4,5 a Taxonomy, Post type or Field group. Or categories of WP normal post?
    2) Is the Element Type (Fire) a Taxonomy or Field Group?
    3) Is ATK & DEF a Field Group?
    4) Can every stat on that card have its own archive page or be filterable, Eg. highest attack 4 star card?(not a big deal if not)

    I’m basically trying to create an archive page that looks like the image above. It displays all Ratings 3,4,5 as the screen shot. Assigning the glow and styling are elementor things i can do with css or theme builder which aren’t an issue.

  • Solved

    Taxonomies are not saved via the frontend. But it works in the backend. Why?

    I would like to use this function to activate my taxonomies via a true/false field. And it works perfectly in the backend.

    function update_post_taxonomy( $post_id ) {
    $myfield = get_field('my_field_name');
    if( $myfield ) {
    wp_set_object_terms($post_id, 'myterm', 'mytaxonomy', true);
    } else if ( empty( $myfield ) ) { 
    wp_remove_object_terms( $post_id, 'myterm', 'mytaxonomy', true );
    }
    }
    add_action( 'acf/save_post', 'update_post_taxonomy', 10 );
    

    But unfortunately not in the frontend via acf_form().
    Could someone help me here? Thanks!

  • Unread

    Taxonomy Select Change ID

    HI,
    I have developed a block that allows the display of posts from a CPT, one of the options i have is to filter these results by a custom taxonomy. The issue is that when the content of the page containing this block is exported from staging to go on to production it loses the link to the choice of custom taxonomy as the IDs are different in the two environments, so is there anyway to store the slug of the taxonomy and do some kind of reverse lookup when it is used on other environments to find and replace the current ID with the new one?

    The code generated currently by the block is:

    <!-- wp:acf/icns {"name":"acf/icns","data":{"colour":"bg-dark-blue","cattowerselect":"1112","numberofposts":"14","icns":"test"},"mode":"auto"} /-->

    cattowerselect”:”1112″ is the ID of the chosen taxonomy which is different on the production site.

    Many thanks

    Steve

  • Unread

    Update multiple values in relationship field not possible

    Hello,
    I am using Advanced Custom Fields PRO Version 6.2.7

    Recently I have noticed that when I want to update a relationship field with multiple values, the whole ARRAY is not saved, but only the first value of the ARRAY.

    I have used this code as a test:
    update_field('menu', array(123,456), $post_id);

    This is the output with var_dump:
    int(123)

    These are my settings for the relationship field:
    {
    "key": "field_60c789afded44",
    "label": "menu",
    "name": "menu",
    "aria-label": "",
    "type": "relationship",
    "instructions": "",
    "required": 1,
    "conditional_logic": 0,
    "wrapper": {
    "width": "",
    "class": "",
    "id": ""
    },
    "wpml_cf_preferences": 1,
    "post_type": [
    "product"
    ],
    "taxonomy": [
    "product_cat:new"
    ],
    "filters": [
    "search",
    "taxonomy"
    ],
    "elements": "",
    "min": "",
    "max": "",
    "return_format": "id",
    "bidirectional_target": []
    },

  • Unread

    about displaying list of childrens in taxonomy field

    i am able to dispplay all the parents like this
    //category manipulation for material and thickness at feaure page
    function feature_hide_child_taxonomies($args, $field){
    if (‘feature_product_select_material’ === $field[‘_name’]) {
    $args[‘parent’] = 0;
    }
    return $args;
    }
    add_filter(‘acf/fields/taxonomy/query’, ‘feature_hide_child_taxonomies’, 10, 2);
    now I want all childrens only but I am unable. please view my other code
    function feature_show_parent_taxonomies($args, $field, $post_id){
    $parent_id = get_field(‘feature_product_radio_size’,$post_id )[‘feature_product_select_material’];

    if (‘feature_product_select_thickness’ === $field[‘_name’]) {

    }
    return $args;
    }

    add_filter(‘acf/fields/taxonomy/query’, ‘feature_show_parent_taxonomies’, 10, 2);

  • Unread

    Creating a Vehicle Make / Model / Year filter for Woocommerce products

    Hi all,

    I am trying to make a ‘Vehicle Fitment’ field group for Woocommeece products using ACF pro repeater.

    Inside the vehicle_fitment repeater I have 3 fields;

    Vehicle_Make – taxonomy field for Product
    Vehicle_Model – taxonomy field for Product
    Vehicle_Years – select field containing years from 1995-2025

    Each product may fit multiple different vehicles, hence why I’m using a repeater.

    The only problem I’m having is then filtering on the front of the site when a customer chooses by Vehicle Make, Vehicle Model & Vehicle Year.

    Could anyone suggest a better layout for this?

  • Unread

    Display ACF on elementor with dynamic tag

    Hi

    I’ve created a custom post type “Job offers” and some custom fields “Job details” with ACF. I want to display the custom field values on each Job offer post. To do so, I used Elementor (Free) and dynamic tags.

    So far I am facing 2 issues :
    – 3 of my custom fields are taxonomies. When using dynamic tags on Elementor, the id of the taxonomy is displaying instead of the value of the taxonomy, even if the configuration of the custom field seems right. My question is : how do I display the value of the taxonomy (ex: type of contract) instead of its id (ex:186).
    – My 2nd issue is that I created some text boxes with ACF and when using dynamic tags on Elementor to display the content of this field for each post, the line breaks seem to disappear. Do you know how to avoid this to happen ?

    Help would be much appreciated :’)
    Thank you

  • Unread

    Custom Types web structure

    Hello! I’m building a website with custom post types thanks to ACF (💖) along with Elementor, but I have a question. I want to maintain a specific structure for the CPT I have created. I have created a post type (surgery) and a taxonomy for it (surgery-cat).
    This has created the following URL for the posts:

    (post type) domain.com/surgery/surgery-name-post

    And for the taxonomy domain.com/surgery-cat/surgery-cat-name

    What I really want is for the URL to have the category name and for the category to work on its own showing the posts (I would do this with Elementor) and remove the post/taxonomy name from both.

    Post type domain.com/surgery/surgery-name-post >>>>> domain.com/surgery-cat-name/surgery-name-post
    Taxonomy domain.com/surgery-cat/surgery-cat-name >>>>> domain.com/surgery-cat-name

    Is it possible to do this?
    Thanks!!

  • Unread

    Custom URL Slug for Custom Post Type with a Custom Taxonomy

    I have created a custom post type, let’s call that Cars.

    I have also created a custom Taxonomy called Car Manufacturers.

    Now, I’d like to create a custom URL for the cars so it’s domain.com/cars/car-manufacturer/{car name}

    Where, cars = custom post type, car-manufacturer = custom taxonomy and car name = the specific post name.

    By default it’s domain.com/cars/{car name}

    What is the correct custom URL structure for this?

  • Unread

    Show acf taxonomy in product page

    hello I create a taxonomy “brand” with acf plugin for woocommerce products
    and now how can I show product brand in their page ?

  • Unread

    Need Some Guidance

    Hi there

    I’ve created a custom post type “Books” Below that I’ve added a Taxonomy “Books” as well. Now on the Add New Book page i am unable to display “Biology” that is a Child Taxonomy. I’ve already added “Biology” at taxonomy page.

    How can i display this on my edit / add book page?

    Regards

  • Solving

    ACF taxonomy and url rewrite

    I created a custom post type ‘products’ using ACF.

    Then, I created the taxonomy ‘product categories’.

    Now, when I click ‘view’ on one of these taxonomies like ‘t-shirts’,

    I end up on this URL: ‘/product-category/t-shirts/’

    I would like my URL to be: ‘/products/t-shirts/’

    So, I tried going to the URL section of the taxonomy select ‘permalink rewrite’ and entered ‘products/’ in the URL slug.

    Now, when I click ‘view’ on ‘t-shirts’, I end up on this URL: ‘/products/t-shirts/’, which is correct, but the page is a 404.

    Am I missing a step?

  • Unread

    Display Taxonomy name

    Hello,

    I’m working on a website with a search bar based on 2 taxonomies, City and Project. From the search bar the user selects a ‘City’ first and then the ‘Project’ dropdown updates based on the companies available in the initial city selected. Once the user click ‘search’, the website redirects them to a result page where all the companies shown are based on the previous selection.

    I need to show on this page a title with the taxonomy name selected for the ‘city’ on top of the page. I have created the taxonomy and gave a key name ‘city_acf’. Is there anyone kind enough to help me sort this?

    Thank you so much in advance.

    Matt

  • Unread

    Getting value of a custom field in a custom taxonomy

    Hi,
    I have created a custom post type “Stories” where I’ve also created a custom taxonomy named “Segment”. Connected to this custom taxonomy I’ve created a custom field “segment_image” (set to array) ruled to be shown if Taxonomy is equal to “Segment”. The idea is that each term will have an image assigned and will be displayed in the post depending on the segment chosen.

    In the back-end everything seems to be connected correctly and the field is showing in the Taxonomy page to upload an image. The problem I’m having is that I can’t find the way to retrieve that image ID or URL in my template page.

    Here is my code:


    <?php
    $args = array(
    'post_type' => 'stories',
    'post_status' => 'publish',
    'posts_per_page' => -1
    );

    $loop = new WP_Query( $args );

    while ( $loop->have_posts() ) : $loop->the_post();

    $segment = get_field('segment_story');
    $segment_bg = get_field('segment_image', $segment);

    echo 'bg: ' . $segment_bg['url'];

    I’ve even created a Taxonomy field type in my custom post type “Stories” called “segment_story” to force getting the term array manually but still nothing.

    I would appreciate any help with this! I’ve checked several ACF documentation pages and also checked some threads here but nothing worked for me so far.

    Thanks in advance!
    I.

  • Solved

    Programmatically set the value of a select2 field.

    Working with a front-end form, I want to programmatically set the value of a select2 taxonomy field after another field is updated.

    I have tried all manner of updating the value but it either doesn’t change or gets set to null. Any ideas? I thought I had a very simple task at hand, but its eluding me.

    This is what I have tried:

    
    const selectedValue = 12; //the id of the term I want to select
    $('#acf-field_5dcc4aa906709').val(selectedValue).trigger("change"); 
    
    var countyfield = acf.get_field('field_5dcc4aa906709');
    countyfield.val(selectedValue); 
    

    The first one should work according to the select2 documentation. This actually sets the value of the field to null.

    The second one I got from the ACF documentation. This updates the field object but does not update the field in the UI.

  • Solved

    Importing ACF

    Hi,

    I am performing an import of more than 500 items with the wp-ultimate-csv-importer free version.

    I managed to import all the ACF fields except for the relationship and taxonomy fields.

    As I read in this post: https://support.advancedcustomfields.com/forums/topic/importing-data-2/, serialized arrays of post IDs are used for relationships, serialized arrays of term IDs are used for taxonomies.

    I am trying to upload a CSV formatted like this:

    Title;Relationships;Taxonomies
    Test;”a:2:{i:0;i:651;i:1;i:649;}”;”a:2:{i:0;i:18;i:1;i:19;}”

    It doesn’t work.

    Is there a way to import these fields? How should the CSV be formatted?

  • Helping

    No Meta Box for Taxonomy Doesn’t Function as Intended

    Expected Behavior:
    I would expect the No Meta Box selection in the Meta Box field on the settings for my taxonomy: [My Taxonomy] > Advanced Settings > Visibility would hide the Taxonomy Options from my post editor.

    Actual Behavior:
    The Taxonomy Meta Box still appears in the post editor. The only way to hide it is to hide it completely by toggling the Show in UI to off, but I still want to be able to see my Taxonomy and terms in the dashboard.

  • Unread

    One field inside of while loop show the same content for every entry

    Hello, I am writing a cpt with acf, and one of the fields, show the exact same text for every post in the CPT (the first one). If I set it as draft it moved to the second.
    The strange part is that every other field in the loop works perfectly, only this one is problematic. The field is ‘testimonial_text’;

    Here is my code:

    // Testimonial Slider Shortcode
    function testimonial_slider_shortcode($atts) {
    $atts = shortcode_atts( array(
    'category' => '',
    ), $atts, 'testimonial-slider' );
    $args = array(
    'post_type' => 'testimonials',
    'posts_per_page' => -1,
    'tax_query' => array(

    array(
    'taxonomy' => 'testimonial_category',
    'field' => 'slug',
    'terms' => $atts['category'],
    'operator' => 'AND'
    )

    )
    );

    $testimonials = new WP_Query($args);
    $output = '<div id="testimonial-slider" class="carousel slide full-width" data-ride="carousel">';
    $output .= '

      ';

      $i = 0;
      while($testimonials->have_posts()) {

      $testimonials->the_post();
      $output .= '<li data-target="#testimonial-slider" data-slide-to="'.$i.'" class="'.($i == 0 ? 'active' : '').'">';
      $i++;
      }

      wp_reset_postdata();

      $output .= '

    <div class="carousel-inner">';

    $i = 0;
    while($testimonials->have_posts()) {
    $testimonials->the_post();
    $post = get_post();
    $person_name = get_field('person_name');
    $testimonial_text = get_field('testimonial_text');
    $company_text = get_field('person_company');
    $person_photo = get_field('person_photo');
    $person_photo_url = $person_photo['sizes']['large'];

    $output .= '<div class="item '.($i == 0 ? 'active' : '').'">';
    $output .= '<div class="inner-testimonial">';

    $output .= '<div class="carousel-caption">';
    $output .= '<div class="block-quote-img">';
    $output .= '';
    $output .= 'test';
    $output .= '<span class="author-text" maxlength="2">' .$testimonial_text. '</span>';

    $output .= '</div>';
    $output .= '<p class="author">' .' - ' .$person_name.' , '.$company_text.'</p>';
    $output .= '</div>';
    $output .= '<div class="img-div">';
    $output .= ''.$person_name.'';
    $output .= '</div></div></div>';
    $i++;
    }

    wp_reset_postdata();

    $output .= '</div><span class="glyphicon glyphicon-chevron-left"></span><span class="glyphicon glyphicon-chevron-right"></span></div>';

    return $output;
    }
    add_shortcode('testimonial-slider', 'testimonial_slider_shortcode');

    // Enqueue styles and scripts
    // Global plugin styles should be added to testimonails slider.css
    // Per project styles should be added to testimonial-project.css
    function testimonial_slider_scripts() {
    wp_enqueue_style( 'testimonial-slider-style', plugins_url( '/testimonial-slider.css', __FILE__ ) );
    wp_enqueue_style( 'testimonial-project-style', plugins_url( '/testimonial-project.css', __FILE__ ) );
    // wp_enqueue_style('bootstrap', 'https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css');
    // wp_enqueue_script(
    // 'testimonial-block-script',
    // plugins_url( 'blocks/testimonial-block.js', __FILE__ ),
    // array( 'wp-blocks', 'wp-i18n', 'wp-element', 'wp-components' )
    // );

    }

    add_action( 'wp_enqueue_scripts', 'testimonial_slider_scripts' );

    // Register Gutenberg Block

    add_action('init', 'wp_testimonial_block_init');

    function wp_testimonial_block_init() {

    register_block_type(__DIR__ . '/build', array(
    'render_callback' => 'theHTML'
    ));

    }

    function theHTML($atts) {
    $args = array(
    'post_type' => 'testimonials',
    'posts_per_page' => -1,
    'tax_query' => array(

    array(
    'taxonomy' => 'testimonial_category',
    'field' => 'slug',
    'terms' => $atts,
    'operator' => 'IN'
    )

    )
    );

    $testimonials = new WP_Query($args);
    $output = '<div id="testimonial-slider" class="carousel slide full-width" data-ride="carousel">';
    $output .= '

      ';

      $i = 0;
      while($testimonials->have_posts()) {

      $testimonials->the_post();
      $output .= '<li data-target="#testimonial-slider" data-slide-to="'.$i.'" class="'.($i == 0 ? 'active' : '').'">';
      $i++;
      }

      wp_reset_postdata();

      $output .= '

    <div class="carousel-inner">';

    $i = 0;
    while($testimonials->have_posts()) {
    $testimonials->the_post();
    $post = get_post();
    $person_name = get_field('person_name');
    $testimonial_text = get_field('testimonial_text');
    $company_text = get_field('person_company');
    $person_photo = get_field('person_photo');
    $person_photo_url = $person_photo['sizes']['large'];
    $output .= '<div class="item '.($i == 0 ? 'active' : '').'">';
    $output .= '<div class="inner-testimonial">';

    $output .= '<div class="carousel-caption">';
    $output .= '<div class="block-quote-img">';
    $output .= '';
    $output .= '<span class="author-text" maxlength="20">' .$testimonial_text. '</span>';

    $output .= '</div>';
    $output .= '<p class="author">' .' - ' .$person_name.' , '.$company_text.'</p>';
    $output .= '</div>';
    $output .= '<div class="img-div">';
    $output .= ''.$person_name.'';
    $output .= '</div></div></div>';

    $i++;
    }

    wp_reset_postdata();

    $output .= '</div><span class="glyphicon glyphicon-chevron-left"></span><span class="glyphicon glyphicon-chevron-right"></span></div>';

    return $output;
    }

    This is the code for the acf register

    // Add Custom Fields
    function add_testimonial_custom_fields() {
    if(function_exists('acf_add_local_field_group')):

    acf_add_local_field_group(array(
    'key' => 'group_testimonial',
    'title' => 'Testimonial Fields',
    'fields' => array(
    array(
    'key' => 'field_person_name',
    'label' => 'Person Name',
    'name' => 'person_name',
    'type' => 'text',
    'required' => true,
    'show_in_rest' => true,
    'wrapper' => array(
    'width' => '50',
    ),
    ),
    array(
    'key' => 'field_testimonial_text',
    'label' => 'Testimonial Text',
    'name' => 'testimonial_text',
    'type' => 'wysiwyg',
    'required' => true,
    'show_in_rest' => true,
    'wrapper' => array(
    'width' => '50',
    ),
    ),
    array(
    'key' => 'field_person_photo',
    'label' => 'Person Photo',
    'name' => 'person_photo',
    'type' => 'image',
    'preview_size' => 'full',
    'required' => false,
    'show_in_rest' => true,
    ),
    array(
    'key' => 'field_person_company',
    'label' => 'Company',
    'name' => 'person_company',
    'type' => 'text',
    'required' => false,
    'show_in_rest' => true,
    ),
    ),
    'location' => array(
    array(
    array(
    'param' => 'post_type',
    'operator' => '==',
    'value' => 'testimonials',
    ),
    ),
    ),
    ));

    endif;
    }
    add_action('acf/init', 'add_testimonial_custom_fields');

  • Unread

    Showing certain post categories on custom post type

    Dear ACF Community.

    I’m struggeling with something that is in fact very simple, and i suppose it’s an easy thing for some of you to solve.

    I have several blog posts for bicycle tours attached to a custom taxonomy for countries.

    I also have set up a custom post type for countries, to write a bit about the country and show only blog posts for this country, according to the category.

    But i don’t get it run, that only blog posts for this country are shown on the country page.

    The URL for the country page would be e.g. https://www.rogonneur.com/country/germany/
    And the Post to appear in the blog teaser section there would be e.g. https://www.rogonneur.com/cycling-to-watch-the-first-freiburg-international-match-in-years/ as it’s only connected to the category “germany”.

    Is this somehow too advanced? I’d appreciate any help!
    Kind regards,
    Dominic

  • Unread

    Display field on single product page

    Hello, I have made a field to add to the Woocommerce attributes. I have added a picture below for more clearancy.

    explaination

    I am trying to display the field on the single product page. I have added the following code to the content-single-product.php template file.

    
    $terms = get_the_terms( $product->id, 'pa_merk');
    		var_dump($terms);
    		
    		$image = get_field('afbeelding_merk', $terms->taxonomy . '_' . $terms->slug);
    		
    		// Display the image if it exists
    		if ($image) {
    			echo '<img src="' . $image . '" />';
    		} else {
    			echo "<p>Foto niet gevonden.</p>";
    		}
    

    What am I doing wrong?

  • Helping

    Bug relationship between taxonomy and users

    Hi,

    I found a bug in the relationship between a custom taxonomy and the users.
    I have a custom taxonomy ‘genres’ with an assigned field group with a field for assigned users.

    Name: ‘rel_users’
    Field Type: User
    Select Multiple: True
    Bidirectional Target Field: rel_genres

    A second field group is assigned to ‘users’ and has a field for assigned taxonomy.

    Name: ‘rel_genres’
    Field Type: Taxonomy
    Appearance: Multi Select
    Bidirectional Target Field: rel_users

    If I assign a user to a genre term, everything is ok.
    term_id: 15
    user_id: 5

    wp_usermeta
    meta_key: rel_genres
    meta_value: a:1:{i:0;s:2:”15″;}

    wp_termmeta
    meta_key: rel_users
    meta_value: a:1:{i:0;s:1: “5”;}

    In the backend the relations are displayed correctly in the user profile and on the taxonomy edit page.

    However, when I make changes on the taxonomy edit page, the target value is changed incorrectly (when I delete, save and reassign the user) so that the assignment in the user profile disappears. When saving the taxonomy term, the bidirectional target field is now saved as an interger array instead of string array.

    wp_usermeta
    meta_key: rel_genres
    meta_value: a:1:{i:0;i:15;} <- integer array!

    wp_termmeta (unchanged)
    meta_key: rel_users
    meta_value: a:1:{i:0;s:1: “5”;}

    It seems that the array with integer values destroys the relationship on the side of the user.

    best regards
    steffen

  • Solving

    Showing all products with a specific taxonomy

    I have created a custom taxonomy (book authors). Now I want to show all book authors and their respective custom fields on a page, how do I do that?

Viewing 25 results - 1 through 25 (of 4,545 total)