Skip Navigation

[Resolved] Show posts' filtered taxonomies within a loop

This support ticket is created 5 years, 8 months ago. 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
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 14 replies, has 2 voices.

Last updated by Shane 5 years, 8 months ago.

Assisted by: Shane.

Author
Posts
#1253077

I have a posts view.
All posts have different taxonomies terms.
All taxonomies have custom fields.
I want to display these posts terms filtered by their custom fields.

So with the good old [wpv-post-taxonomy] I can't filter it by its custom fields... or can I?

I tried with a taxonomy view with a query filter (via shortcode) that targets only terms custom fields. But this doesn't work since the View, which I put in 'Templates for this View', doesn't count the terms applied to the post!

Let me try this way:

Posts: Resource1, Resource2, Resource3, Resource4, Resource5
Taxonomy terms: School1, School2, School3, School4
Taxonomy terms custom field: Language1, Language2

Post View Shows

Resource1 - School1 - School2(Language1)
Resource2 - School3(Language1) - School4

Now, how do I output ONLY School2 and School3 based on their custom fields (Language1)

I hope this is clear enough, thanks for your help.

p.s.
no I can't give access to the website unfortunately, it's a client's live one.

#1253383

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Leonardo,

Thank you for contacting our support forum.

This one isn't actually possible to achieve unless you take the value from the url and use some custom code to display the names of the items in the url. It will require the writing of a custom shortcode to achieve.

If you are not aware of how to do this please let me know.

Thanks,
Shane

#1253749

Yes please, if you can elaborate a bit more would be great.

Also, doesn't seem like a weird use to me, right? If I'm able to add custom fields to a taxo term, I should be able to get it in some ways don't you think?

#1254373

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Leonardo,

Thank you for the patience.

Try this custom shortcode I wrote.

// Add Shortcode
function cust_get_term_name( $atts ) {

	// Attributes
	$atts = shortcode_atts(
		array(
			'field' => '',
			'value' => '',
			'taxonomy' => '',
		),
		$atts
	);

	$term = get_term_by($atts['field'],$atts['value'],$atts['taxonomy']);
	
	return $term['name'];

}
add_shortcode( 'cust_get_term_name', 'cust_get_term_name' );

Add it to the Toolset custom shortcode section in Toolset->Settings->Custom Code and activate it.

Example usage would be.
[cust_get_term_name field='slug' value='[wpv-search-term param="url-param-for-search"]' taxonomy='taxonomy-slug']

Please try using this shortcode. Also is this view a parametric search ?

Let me know.
Thanks,
Shane

#1254407

Thanks for this! Unfortunately, I think I need a bit more help to understand how to use it.

So, I have a posts view, with another view inside (taxonomy view). Do I need to add the shortcode inside the taxo view right?

and regarding the shortcode

[cust_get_term_name field='slug' value='[wpv-search-term param="url-param-for-search"]' taxonomy='taxonomy-slug']

field is for the taxonomy custome field slug?
and param is for? A query search like Taxonomy term ID is set by the URL parameter "terms-filter" ?

I'm a bit confused

in my case:

Posts: Resource1, Resource2, Resource3, Resource4, Resource5
Taxonomy terms (slug=schools): School1, School2, School3, School4
Taxonomy terms custom field: Language1, Language2

Post View Shows

Resource1 - School1 - School2(Language1)
Resource2 - School3(Language1) - School4

[cust_get_term_name field='language1' value='[wpv-search-term param="school-search"]' taxonomy='schools']

Is this right? Or am I missing something?

#1254495

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Leonardo,

Would you mind allowing me to have access to the site so that I can have a full understanding of your setup ?

The private fields will be enabled for your next response.

Please let me know the page where the view is setup.

Thanks,
Shane

#1255555

any chances you can give me some hints? Like I said in the very first post, I can't give access to this website since it's a live client one.

I can surely create a test env but if you can let me know what I did wrong first would be great

#1257289

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Leonardo,

The taxonomy view is the one listing out the terms for the post?

If so then you need to add the shortcode to the taxonomy view.

Thanks,
Shane

#1258241

No it's not, that's the whole point.

A view shows the posts, another view in it, it's supposed to show the taxonomies of the posts.
I was trying to ask HOW use the shortcode with my settings since it's not very clear 🙁

let's try again, in my case:

Posts: Resource1, Resource2, Resource3, Resource4, Resource5
Taxonomy terms (slug=schools): School1, School2, School3, School4
Taxonomy terms custom field: Language1, Language2

Post View Shows

Resource1 - School1 - School2(Language1)
Resource2 - School3(Language1) - School4

[cust_get_term_name field='language1' value='[wpv-search-term param="school-search"]' taxonomy='schools']

Is this right? Or am I missing something?

#1258571

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Leonardo,

It seems I would need to modify the code a bit but I need to see an example to guide how I should modify the code.

Could you setup the test site and let me know once I can login and have a look ?

Please let me know the appropriate urls and the scenario on which you need your expected results.

Thanks,
Shane

#1260329

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Leonardo,

I'm still a little confused.

Let me get this straight you want to filter your post view by the taxonomy custom field correct?

Please let me know.

Thanks,
Shane

#1261831

I understand is tricky, but I can only post again my initial request

So with the good old [wpv-post-taxonomy] I can't filter it by its custom fields... or can I?

I tried with a taxonomy view with a query filter (via shortcode) that targets only terms custom fields. But this doesn't work since the View, which I put in 'Templates for this View', doesn't count the terms applied to the post!

Let me try this way:

Posts: Resource1, Resource2, Resource3, Resource4, Resource5
Taxonomy terms: School1, School2, School3, School4
Taxonomy terms custom field: Language1, Language2

Post View Shows

Resource1 - School1 - School2(Language1)
Resource2 - School3(Language1) - School4

Now, how do I output ONLY School2 and School3 based on their custom fields (Language1)

So... I don't want to filter the posts!! I want to filter the posts TAXONOMIES! Only show posts' taxonomies terms that have specific custom fields.

#1262707

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Leornardo,

"So with the good old [wpv-post-taxonomy] I can't filter it by its custom fields... or can I?"

No you can't.

Post View Shows

Resource1 - School1 - School2(Language1)
Resource2 - School3(Language1) - School4

For this the only way I can think of filtering this is to use a taxonomy view and then use a shortcode parameter in that view to filter the taxonomy by custom field.

The only problem is where would that value come from unless you want to add a custom field to the resource cpt that would match the school custom field.

Thanks,
Shane

#1264937

mmh the taxo view is a way, the problem is, how do I tell the taxonomy view: "show me the terms linked to the post and fitlered by their (terms) cf?".

Maybe I'm wrong but doesn't seem so weird to me? If I'm able to show posts' terms (wpv-post-taxonomy), why I'm not able to FILTER those terms by their attributes? Like: [wpv-post-taxonomy cf="custom-field1, custom-field2"] is it possible to extend this shortcode? Because it already checks what taxonomy terms the post has, I just need a way to FILTER these terms.

Does it make sense at all?

#1266925

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Leornardo,

how do I tell the taxonomy view: "show me the terms linked to the post and fitlered by their (terms) cf?".

You are able to tell a taxonomy view to filter by the current post and display only the taxonomies of that post.

To filter a taxonomy by its custom fields you must use a taxonomy view. Now this view can be filter by both the Current post and the taxonomy custom field.

This is why I said if you want a specific taxonomy based on the custom field, where would this value come from? It would need to be provided manually or through some dynamic means.

So what you are trying to achieve is somewhat possible but we need to know where the value to filter the taxonomies by the custom field will be coming from.

Thanks,
Shane