Skip Navigation

[Resolved] Displaying a view that has post with the same custom field value as the current

This support ticket is created 5 years, 5 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
- 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)

This topic contains 4 replies, has 2 voices.

Last updated by alvinc 5 years, 5 months ago.

Assisted by: Nigel.

Author
Posts
#1331373

Tell us what you are trying to do?
I have a single post and I want to show another post that has the same custom field value as this post. The single post is in district 10 and I want to display other post from the same district. My client doesnt want to use maps, so I am trying to do the nearby thing by using district.

Is there any documentation that you are following?
Can't find any.

Is there a similar example that we can see?

What is the link to your site?
hidden link

#1331419

Nigel
Supporter

Languages: English (English ) Spanish (Español )

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

Hi Alvin

So you have a custom field for district, and when viewing a post you want to show other posts that have the same value for district?

My first instinct is that it makes more sense for district to be a taxonomy rather than a custom field, but in any case the principles are the same.

Create a View to show the related posts.

Include a Query Filter for the district field and specify that the value should come from a shortcode attribute. Give the attribute a name that makes sense to you. In my example, I'm going to specify the attribute will be "filter".

Now insert the View into a template to display the posts. You'll need to edit the shortcode that inserts the View to add the attribute you specified in the last step and provide the value of the field for the current post, so it should look something like this:

[wpv-view name="things" filter="[types field='options' output='raw'][/types]"]

You can read more about passing values to Views filters here: https://toolset.com/documentation/user-guides/passing-arguments-to-views/

#1331579

Hi

How do I provide a value to the field when it is actually set by the current post? What do I put in 'options'? Thanks.

#1331609

Nigel
Supporter

Languages: English (English ) Spanish (Español )

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

In my example I'm using a custom field 'options', but you would be using whatever the custom field is that both posts are using for district, presumably called something like 'district'.

#1331959

There was a conflict with the naming of the field that's why it didn't work! So now it works. My issue is resolved now. Thank you!