To vote or comment, enter your email and we'll send a magic link


Sort by featured then by x


I'd like to have an easy way to sort by featured products in the sort menu and then sort the remaining items by 'x' (date, title, etc.). Struggled to find this but seems like something people would want.

2 years ago

Comments (10)

I can help you with the coding here. Can you give me a way to contact you?

2 years ago

I tried to post the code here but this site is blocking any code samples going up >-<

2 years ago

There is a bit of an explanation of making sort facets here: https://facetwp.com/help-center/facets/facet-types/sort/ without any code.

2 years ago

My code can be pasted into any php template file or regular file. Dear programmers. I can help people with code. Can you somehow allow me you post in the support area or here. If people can share code online it will make using your plugin easier.

2 years ago
<form method="GET" style="text-align:right">
    <select class="en1" name="orderby" id="orderby2">
        <option>Date (Newest to Oldest)</option>
    <button class="en1" type="submit">OK</button>
    <button class="en2" type="submit">Apply</button>
2 years ago

Sorry it's a total mess but it was the only way I could paste it here. You can just have the original form with whatever search filters/dropdowns you like this way. Each span class en here can be a different set of terms. You can also make multiple select dropdowns just remember to set different ids. (orderby1, orderby2, etc.)

Hope they can add more code samples on the sort page. It took me almost a 6 months to figure out how to do this as there weren't any good code samples I could easily find anywhere.

2 years ago

Thank you for your offer to help and the code snippet. I don't want to post my contact online though, but would be nice to have a way to get help/share ideas. I'll try to put together what you sent to see what you meant, as I'm not sure I follow.

What I was hoping for was some query to sort by featured products first (by date) and the rest of the items by date after. Something like <code>meta_key' => '_featured', and "orderby" => array( 'meta_value_num' => 'DESC', 'date' => 'ASC' ). </code> In the visual builder I can't sort out how to do that or if it's possible as the formatting is different and I can't get anywhere with it. It's strange that sorting by featured products is a challenge and not an option out of the box.

2 years ago

Try using 3 backticks (backtick: `) above and below your code example.

echo 'hello world';
2 years ago

Assuming _featured is an existing custom field, you could use it within the "Query" section of the layout builder: https://d.pr/i/0VT7wV

2 years ago

Thanks Matt, that helps. But is there no way to do it with the existing 'featured' products term from Woo, so starred products can be used?

2 years ago