Skip Navigation

[Waiting for user confirmation] order by brand

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 6 replies, has 1 voice.

Last updated by Minesh 2 days, 22 hours ago.

Assisted by: Minesh.

Author
Posts
#2812744

Tell us what you are trying to do?
WooCommerce added the option to choose brands for products, creating a brand taxonomy. I'm trying to use the Toolset Views block to display products from a category and order them by brand, but I don't know how to do it.

Is there any documentation that you are following?
I searched the documentation by I don't found the solution.

Is there a similar example that we can see?
no

What is the link to your site?
eulalialatorre.cl

#2812768

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Do you mean you want to group products by brand?

For example:
Brand 1:
- Product 1
- Product 2
- Product 3
Brand 2:
- Product 4
- Product 5
- Product 6
Brand 3:
- Product 7
- Product 8
- Product 9

If yes, can you please share details on what page exactly you want to display it and under what section and share admin access details or for what brands you want to group products.

If no: can you plesae clarify your exact requirement.

Please share admin access details and problem URL.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2812815
tienda v2 eulalia (1).png

I have two primary product categories, each containing various brands. My goal is to arrange the products within each category by brand, ensuring that all products from a single brand appear consecutively in the display grid.

Currently, I'm using a Toolset View block to showcase products: one block for each main category. The challenge I'm facing is how to configure the internal sorting within these views to order by brand, rather than the default sorting by title or date.

As a temporary workaround, I've manually set the order and used the 'menu order' option, but this is proving to be cumbersome. I'm looking for a more efficient solution to automatically sort products by brand.

#2812903

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I will require problem URL and admin access details. Once I review your current strucure then I will be able to guide you in the right direction.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.

#2812952

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I checked the structure you have and I can see you have "product_brand" and you want to display product posts order by taxonomy "product_brand".

WordPress don't support ordering/sorting the results by taxonomy. If you see the orderby options given with the WordPress Doc, you will not see any option to order the results by taxonomy term.
- https://developer.wordpress.org/reference/classes/wp_query/#order-orderby-parameters

The only option is, you should create a custom field that should hold the same term name (brand name) of "product_brand" taxonomy you assign to your post and then use this custom field to order by your posts.

#2812979

Great idea!

I created the "marca_producto" field within the "Products" post type in WooCommerce.

How could I "copy" the value of product_brand into this new field?

I understand this would only happen for new products I add.

Could you give me some guidance?

Thanks!

Me

#2813073

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Before performing any steps:
*** Please make a FULL BACKUP of your database and website.***

Here is a custom function that should help you to update the existing posts.

You can add the following code to "Custom Code" section offered by Toolset or try to add it to your current active theme's functions.php file.

function update_toolset_marca_producto_field() {
    $args = array(
        'post_type'      => 'product', // Change this to your actual post type
        'posts_per_page' => -1,
        'post_status'    => 'publish',
    );

    $posts = get_posts($args);

    foreach ($posts as $post) {
        $post_id = $post->ID;

        // Get the assigned product_brand terms
        $terms = wp_get_post_terms($post_id, 'product_brand');

        if (!is_wp_error($terms) && !empty($terms)) {
            // If multiple terms, you could concatenate or just use the first one
            $brand_name = $terms[0]->name;

            // Toolset custom field uses 'wpcf-' prefix
            update_post_meta($post_id, 'wpcf-marca_producto', $brand_name);
        }
    }
}
add_action('init', 'update_toolset_marca_producto_field');

To avoid running this code on every page load:

Either wrap it in a condition like this:

if (is_admin() && isset($_GET['run_toolset_brand_sync'])) {
    update_toolset_marca_producto_field();
}

Then trigger/run the above code only once by visiting:

<em><u>hidden link</u></em>

Once you see the existing posts are get updated and it has correct brand name filled with the custom field "marca_producto", you can set your view to order by custom field "marca_producto".