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'
)
)
);
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.