Navigation überspringen

[Gelöst] Designating a post as featured within a category

This support ticket is created vor 6 Jahren, 9 Monaten. There's a good chance that you are reading advice that it now obsolete.

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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Dieses Thema enthält 5 Antworten, hat 2 Stimmen.

Zuletzt aktualisiert von Nigel vor 6 Jahren, 9 Monaten.

Assistiert von: Nigel.

Author
Artikel
#628003

Tell us what you are trying to do?
I have a CPT called Tools.
Tools has a Custom taxonomy called Tools Categories.

I would like to set a field that makes a Tool Post "featured" within a specific category - maybe in more than one category.

I know I can just make a checkbox field called Featured, but this would make the Tool featured in all categories. I want to be able to set the "featured" field separately per post and per category.

E.g.
Tool 1 is featured in category 1 and category 2
Tool 2 is featured in category 2 and category 3
Tool 3 is not featured in any category

I'm not sure how to do this with CPT and taxonomies - do I need to make another post type instead of my taxonomy and use relationships?

Is there any documentation that you are following? I've done some searches but nothing I've found covers this

Is there a similar example that we can see? Lots of directory sites do this

What is the link to your site? It's my client's site and is protected at the moment. If necessary I can recreate what I've done so far in a fresh install.

Thanks in advance for your help.

#628200

Nigel
Supporter

Sprachen: Englisch (English ) Spanisch (Español )

Zeitzone: Europe/London (GMT+00:00)

Hi Tim

Before recommending a solution it would be helpful to know how and where you intend to use this information.

It may require storing term IDs or slugs, I don't have a solution in mind because I'm not sure what you will be displaying.

#628292

Hi Nigel

The idea is to display tool category archives with featured items highlighted at the top of the archive.

For example:
Category 1
Tool 1
Tool 2
Tool 3
Tool 4

Category 2
Tool 4
Tool 3

Category 3
Tool 5
Tool 3
Tool 4

So a tool can be highlighted at the top of a particular category.

#628640

Nigel
Supporter

Sprachen: Englisch (English ) Spanisch (Español )

Zeitzone: Europe/London (GMT+00:00)

Hi Tim

I've been giving this some thought but it is not so straightforward because unlike for Views, Toolset doesn't provide any filters to modify custom archive queries that we could use to manipulate what posts are returned and their sort order.

I'm going to take a break from this now and return to it later when I have attended to some other tickets in my queue and I'll get back to you when I can.

#628984

Hi Nigel,

Thanks for looking at it. I see how to do it with another Custom Post type and a post relationship but it seems like overkill for achieving something that should be relatively simple. That would clutter up the admin area for the client and it's something I want to avoid if possible.

But saying that, the only solutions I can think of involve bad usability.
E.g. maybe I can add a field to the taxonomy. Into that field you would enter a comma delimited list of the post IDs that are featured in that category. Then somehow use that to sort so that the featured items appear first and are given a different class. In that case the user would have to find the post id for the featured item and enter it in a specific format into the taxonomy field. - not great usabilty.

Anyway, if you can come up with something I'd appreciate it. I've got a couple of weeks before it becomes urgent, and if we can't do it I'll just have to tell my client that featured means featured in every category.

Thanks
Tim

#630075

Nigel
Supporter

Sprachen: Englisch (English ) Spanisch (Español )

Zeitzone: Europe/London (GMT+00:00)

Screen Shot 2018-03-30 at 13.55.36.png

Hi Tim

Yes, the usability is a big issue here.

Also, you cannot filter custom archives the same way you can filter Views with wpv_filter_query.

Regarding usability, I would use taxonomies. You could add child terms to your existing tool category terms, something like in the screenshot.

Or you could add those "Featured in..." terms to a separate taxonomy if that made sense.

But, there is not much that's very helpful in the orderby parameters available for the query: https://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters

The only thing you could use would be to orderby post__in where you perform a custom query to get the featured posts for that category, and work with the main query to manipulate these and create the post__in array from these, which you feed into the query arguments for a posts taxonomy query to be run a 3rd time, spitting out the results in the required order.

But even that doesn't help you style the featured tools distinctly.

I think this requires you writing a custom PHP template for the tool category archive that includes the custom queries and where you have control over the output so that you would be able to style the featured tools within the category differently.

Apart from setting up the initial taxonomy, I don't think Toolset can help getting the result you want for the output.