Display an entry in a view depending on URL

By: Malcolm O\'Reilly | Asked: 09/24/2024
ForumsCategory: Code HelpDisplay an entry in a view depending on URL
Malcolm O\'Reilly asked 3 months ago
Hi. I have various blog pages with a different bird name in each URL. I would like to display the same view on each page, but the view set up to display a matching form entry for that specific blog (eg: the 'eagle' form entry is displayed only when 'eagle' appears in the blog post URL). Is this even possible? Or would I be better creating a different view for each bird species, or using shortcodes? TIA
4 Answers
Victor Font answered 3 months ago
You can do this with a single view filtered on bird species. You pass the parameter in the URL: my-view.com?species=eagle. In your view filter you set species to equal [get param='species']
Malcolm O\'Reilly answered 3 months ago
Thanks! I'm not very familiar with get param. When you refer to the URL 'my-view.com?species=eagle'?, do you mean the URL of the blog post?  Eg: https://arcguiding.com/blog/nature/scottish-crossbill/ I get roughly how the filtering is set up, but not the previous part:  how to pass the parameter. This doesn't mean changing the corresponding blog post URL does it?  Thanks for your patience. 
Victor Font replied 3 months ago

You asked about how to filter a view. I already told you, views have nothing to do with blog posts.

Rob LeVineRob LeVine answered 3 months ago
I think you some miscommunication here, so I'll give it a shot. What I think you're asking for is a way to parse the URL (not the parameters) and use the result to filter a view. There are two ways I can think of to do that, the first will definitely work though it's big-time custom and the second I assume will work. The first is to make the content of your view a shortcode and the shortcode parses the URL, figures out which bird type, and then returns the HTML needed to generate the output. The second is to use frm_where_filter. You set up your view however you want and use that hook to set the bird parameter based on the URL.
Malcolm O\'Reilly answered 3 months ago
Hey thanks Rob for your help. It's all fixed now, super simple. I'm no expert - I was trying with the Gutenberg Formidable Views block and hadn't understood that the value could be passed via the shortcode instead. All fixed now, thanks 😁 (also ran into a big ol bug cos using an old version of the plugin) 

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right