Home › Forums › General Issues › Select posts by Category && Custom Field? › Reply To: Select posts by Category && Custom Field?
I’ve created a Field Group called Brands, in that field group I’ve added a field with a field name of ‘select_brands’ of type Checkbox (to be able to select multiple). In the choices I’ve added this:
bolou : Bolou
c6 : C6
deakin francis : Deakin Francis
fope : FOPE
piero milano : Piero Milano
From this I generate a drop down on the front page, along a second drop down generated from categories (the built in widget in the admin interface).
So, now I can pick – from two different drop downs – a combination of both Brand and Category. But, – I’ve now tried for three days to get the posts from the DB without any luck (yes, luck is actually what I’m counting on now, ’cause nothing seem to make sense).
Now, from the 3.456.745 different versions of an $args array I’ve tried, none work. Now, I need some help understanding what parameters I actually need to put where, as I simply can’t grasp why this is so hard to get going.
I would expect the following to get me; posts of custom post type ‘jewellery’ with a category of whatever is selected in the category drop down ($category is an integer from the option value in the drop down) that is also of a specific Brand ($brand is a string from the above options from the custom field).
$args_jewellery = array(
'post_type' => 'jewellery',
'numberposts' => -1,
'tax_query' => array(
array(
'taxonomy' => 'category',
'terms' => array( $category )
)
),
'meta_query' => array(
array(
'key' => 'select_brands', <-- IS THIS RIGHT?
'value' => $brand <-- AND IS THIS?
)
)
);
How do the fields below relate to my custom post type and its value?
'meta_query' => array(
array(
'key' => 'select_brands', <-- ?
'value' => $brand <-- ?
)
)
And WHY isn’t this working? What is it that I’m totally missing here … ?
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!
Are you building WordPress sites with ACF and @BeaverBuilder, and wanted to use your ACF Blocks in both the block editor and Beaver Builder?
— Advanced Custom Fields (@wp_acf) May 10, 2023
The BB team recently added support for using ACF Blocks in Beaver Builder. Check it out 👇https://t.co/UalEIa5aQi
© 2023 Advanced Custom Fields.
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 Cookie Policy. If you continue to use this site, you consent to our use of cookies.