Using a Paragraph field value as a View filter

I am attempting to create a view and paragraph combination that allows for site authors to customize the content that they want to display.

What is currently working:

  • Within my site is the content type of Article
  • I have a view, called News, that is set up to display the published Articles.
  • I created a Paragraph called Article Scroller (article_scroller) that uses a Views reference field (field_view_ref_news) to display the above view.

The above setup allows authors to add the News view to any page, such as a Basic Page or another custom content type. This is all working great.

Where I’m stuck:

I want to take this a step further and allow for the content author to define a filter for the view, such as a location. To do this, I added an Entity Reference field to my Article content type called “Location” (field_location). This is populated with a value from a taxonomy list of states (e.g. Texas).

I then added this same field (field_location) to my article_scroller paragraph.

The idea is that an author would add Texas to an article, and then if they wanted to customize the view to show Texas articles only, they would also define this term within the paragraph.

From there, I’m not sure how to proceed. I’m pretty sure I need to add some kind of relationship and contextual filter here, but am struggling because the term/tid is not going to appear within the URL, and the options under “Provide default value” don’t seem to be relating to what I want to do (at least, nothing I’ve tried from other posts and research has seemed to apply).

Another confusing thing is that I only have my one “field_location” field, but within the view, it appears as two different fields – one under the “Content” category and the other under the “Paragraph” category, which makes sense, but seems to complicate the contextual filters even more as I have to choose between “Content: Location” and “Paragraph: Location”.

I know that one alternative method would be to create a view page/block for each location, Texas, California, New York, etc. I am just hoping I can do something a bit more dynamic.

This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

Using a Paragraph field value as a View filter

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.