Archived topic
Filter custom post type archive with a meta key
9 replies · Started by George on May 1, 2021
I want to display a custom post archive according to whether the simplefavorites_count meta key has a value and then I want to order posts according to that meta key number. Is it possible to achieve that with the new templating system in GP2? And how should the results be displayed? Obviously, I want to be able to keep the default archive with no filtering, as well.
H there,
if you're using Content Template then you have the Apply to: Post with Custom Field. You can then set the Display Rules for your Custom Post Archive.
Hey Dave. Let me explain a bit more. I have already created a custom content template for the custom post type and displaying that conditionally on the custom post type archive page. Now, I want to be able to display a filtered version on a different page with the conditions I described. When I do what you say and select to display that on a certain page (a normal WP page), I get no posts displayed, obviously because the conditional needs to reference the proper archive page which is already taken, if you know what I mean.
Hmm.. i cannot see how you can have both types here - as they both would be using the same archive template.
The only thing i can think of is that you need a separate taxonomy term for the second view.
Yeah, that's what I thought, too. Could it be something that could be added to GP? Like some sort of a query builder, perhaps?
It is something we're looking into - but it may be an updated version of WP Show Posts - being block based, or a query builder for the GB Pro Grid Block... lots of moving parts here and we're still investigating the best possibility.
Yeah, I understand, that would be awesome, though!
Thanks, David.
Totally :)
You're welcome
Hey, David, sorry to come back to this.
Let's say I create a custom query for the posts I want to display with the help of a query generator. Would it be easy to integrate that into the GP templating system so that it could be displayed in a block template? Would that make sense? Maybe a way to copy the template files that power the content template and create a new one?
Personally i think the easiest approach is to set a custom taxonomy term as opposed to a straight forward custom field. Then you don't have to do any complex template and query building.
But i did find this stackexchange question which seems to be along the same track:
https://wordpress.stackexchange.com/a/270260
You can build the custom template based on the GP Archive PHP - as long as it has the generate_do_template_part function then there should be no issues using a Block Element Content template: