OK, day three of trying to figure this one out.
Is this simply not possible to do in WP with custom fields!?
For the sake of needing this at a later point:
$field_key = "field_5925c714d03e7"; // <-- Find this by turning on Field Keys under Screen Options in admin interface
$field = get_field_object($field_key);
if( $field ) {
echo '<select id="brands" name="brands" class="brands" autocomplete="off">';
echo '<option value="-1">All</option>';
foreach( $field['choices'] as $k => $v ) {
echo '<option value="' . $k . '"';
if ( $k == $brand ) {
echo ' selected';
}
echo '>' . $v . '</option>';
}
echo '</select>';
}
Thanks, John, but I have to adapt this to my code to fully understand it:
I have a range of jewellery (using a Custom Post Type = jewellery) that I separate by Category (using the built in Categories of WP) and Brands (using a custom field to select the brand in the custom post type).
From that I create two separate drop downs: Category with values of IDs of categories, and Brands with values of strings.
So if the user select a Brand from one of the selects and a Category from the other select, the code you provide should look like this, right:
'post_type' => 'jewellery',
'tax_query' => array(
array(
'taxonomy' => 'category',
'terms' => array( $category ) // <-- THIS I GET FROM $_GET['c']
)
),
'meta_query' => array(
array(
'key' => 'select_brand', // <-- WHAT DO I PUT HERE (THE CUSTOM FIELD VALUE, this is what I named it.)
'value' => $brand // <-- THIS I GET FROM $_GET['b']
)
)
It’s a select.
What I would ideally like is a copy of the Category widget (just with Brands instead), but I can’t seem to get my head around it. So therefore I’m trying to use a custom field instead, but I’m having serious trouble figuring out how to retrieve post using multiple ‘parameters’.
I’ve been trying something in this direction:
$args_jewellery = array(
'post_type' => 'jewellery',
'category' => $category,
'numberposts' => -1,
'meta_query' => array(
array(
'key' => $brand
// 'compare' => 'EXISTS'
)
)
);
The missing screenshot.
Hi James,
I’m basically trying to recreate the functionality of the Categories Widget under posts – where you can tick a category or add another if needed.
Normally I would have to get into the ACF plugin and add whatever I need in there. But the client would probably find it way to confusing.
The client will continuously add jewellery, and in that process they should be able to add new brands as they go. So I was just trying to add a screenshot of the Category widget (used in the right side of the admin under posts).
Does is make sense?
5.5.14 PRO. But I found out, that I could actually just drag the meta box to the right. But still can’t drag it up below the title though …
I have the exact same issue here. And trying to use Side, I would expect it to move to the right (second column). Nothing happens.
So when some one else says, it’s working here, then the problem is solved?
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.