Support

Account

Home Forums Front-end Issues Only list custom post types that match sub field taxonomy Reply To: Only list custom post types that match sub field taxonomy

  • I think I have solved it.

    From what I understand for a taxonomy the value mst be the ID rather than the name or slug or whatever, so since I need to use the name I need to convert that to the ID. I found that I could do this using get_term_by();

    This is the portion of code I needed to change:

       // Get term by name 'windows' in custom taxonomy 'product-types'.
        $termId = get_term_by( 'name', 'windows', 'product-types' );
        
        // compose our query arguements
        $args = array(
            'post_type'     => 'colourswatch',
            'meta_query'    => array(
                array(
                    'key'       => 'colour_swatch_$_availability', // repeater_$_subfield
                    'value'     => $termId->term_id, // translate the term name into its ID
                    'compare'   => 'LIKE'
                )
            )
        );