Home Forums General Issues Woocommerce Brands – Taxonomy & Checkbox


Woocommerce Brands – Taxonomy & Checkbox

  • Hi all,

    I’m relatively new to ACF but I’ve been finding the documentation ever so helpful. However, on this occasion, I’m not sure there’s anything there for me. Apologies if the answer to this is simple.

    I’m using the Woocommerce Brands plugin, which adds ‘product_brand’ as a taxonomy.

    To this taxonomy, I’ve added 3 custom fields:

    Featured (Checkbox, tick if it’s featured)
    Image (to use as a background image)
    Description (text area)

    Now, I don’t want to query the posts within the taxonomy. I want to get the taxonomies themselves, and only if the “Featured” checkbox is checked.

    Literally, I have no idea how to do this. I’ve been on all day looking for solutions, and it seems beyond my remit.

    Do I need a WP_Query or do I need get_terms or ???

    Any help would be much appreciated!

  • Hi @tony-hardy

    I’m afraid there’s no easy way to query taxonomies. If you want, you can loop through the terms and check one by one which terms that have the featured field enabled. This thread should give you more idea about it:

    I hope this helps ๐Ÿ™‚

  • Hi @james

    Thanks for your reply! In the example linked to, the first line has:

    $location_term = get_term( 'london', 'location' ); // Get term object for your chosen location

    I’m being thrown by that, as I’m not looking specifically for a match of ‘london’ or that level, just the fact that my Featured checkbox is checked. Does that mean the first line of mine should be?

    $brand_term = get_term( 'featured', 'featured' ); // Get term object for your chosen brand_term

    Or am I looking for a different match?

  • Hi @tony-hardy

    The link I gave you is using the taxonomy field type instead of the checkbox. I believe you don’t need to use that line of code for the checkbox field type. Maybe something like this:

    // Loop through all terms
    foreach ($terms as $term){ 
        // Get the featured value. Please check:
    	$term_featured = get_field('featured', $term); 
        //Check if it's featured
            // Add this term object to an array. Don't forget to initialize
            // it first.
            $matching_terms[] = $term;

    I hope this helps ๐Ÿ™‚

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.