How to create another version of the Category widget?

I need to handle both Brands and Categories in WordPress. So I thought I would create a new copy of the Category widget – just with Brands.

I’ve tried various workarounds, including tags, custom fields etc. But I can’t seem to figure out how to retrieve posts using multiple parameters.

So, having a widget for the categories and another for the brands, and a simple way to only retrieve posts that have both set would be what I’m trying to achieve.

I’ve tried using tags, adding Brands to the Categories (a mess), Advanced Custom Fields (ACF) …

How would I go about doing this the proper way in WordPress?

COMPLETE SCENARIO DESCRIPTION OF WHAT I’M TRYING TO DO:

  1. I’d like to set both a category and a brand for a custom post type (product).

  2. On the front end I’d like to create two separate selects (one for the Categories and another for the Brands)

  3. The user make any combination of selections (all in one, and a specific in the other, or all in both … yeah, you get it). Then click an arrow, and reload the page with the new parameters.

I’ve managed to fix all the creation of the selects (apart from the values of the custom fields of course, hence the question), and the url params, reload etc. I’m just stuck on the back end of things, and the retrieval of the correct posts.

I’m doing this to get a drop down of my custom post types (using wp_dropdown_pages to get custom post types, yeah talking about naming things and what they can actually do!). How would I do this for taxonomies?

$args_brands = array(
    'post_type' => 'brands',
    'exclude' => 1,
    'value_field' => 'brand_select', <-- GET ACTUAL CF VALUE (not some just 'some' number)?
    'select' => false,
    'hide_empty' => 0,
    'selected' => $brand,
    'class' => 'brands',
    'show_option_no_change' => 'All',
    'echo' => false
);

$brands_dropdown = preg_replace(
    '^' . preg_quote( '<select ' ) . '^', 
    '<select autocomplete="off" ', 
    $brands_dropdown
);

$brands_dropdown = wp_dropdown_pages( $args_brands );
echo $brands_dropdown;

0

Leave a Comment