Skip Navigation

[Resolved] Is it possible to set the custom field data to be queries in the view

This support ticket is created 5 years, 10 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 8 replies, has 2 voices.

Last updated by matthewL-7 5 years, 9 months ago.

Assisted by: Nigel.

Author
Posts
#1208930

Hi,

I have a view that does the the following query filter at present:
"Select posts with taxonomy:
Categories the same as the page where this View is shown"

This lets me set the category in the view on the page when I use it, so each time I use this view I can pull data for a different category if I choose to in a post.

However, I have another view where I want to do a similar thing but with a custom field.

Same principle i want to set the custom field data on the view when I use it on a page. I can't seem to see a way to do this with a custom field? Is it not possible?

Thanks.

#1209267

Nigel
Supporter

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

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

You would be setting a custom field value on a page, just to pass that value to the View to be used in a Query Filter?

It sounds like what you need is to pass the custom field as a View shortcode attribute, and wherever you insert the View you can provide a different attribute as required.

Say you had a custom field "status", and your View has a Query Filter for status. In the options for that filter you can specify that the value should come from a shortcode attribute. It would likely suggest something like wpvstatus for the attribute, but you can always change this.

Then when you insert your View you specify the status for that particular occurrence of the View, e.g.

[wpv-view name='some-view' wpvstatus='special']

See https://toolset.com/documentation/user-guides/passing-arguments-to-views/#controlling-the-filter-with-shortcode-attributes

#1210709

Great thanks! This helped.

A question on this, I want to use a custom field which will be the same for all the results outside the loop start and end of the loop but in the loop editor. As like a heading.

The custom field does not work though, is there a way to get this to work?

Cheers.

#1211142

Nigel
Supporter

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

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

I'm not sure what you mean. Where does this custom field come from?

When you pass a variable to a View as a shortcode attribute (e.g. wpvstatus in my example above) then you can output that variable anywhere in the Loop Editor using the wpv-attribute shortcode (https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-attribute).

If the page where you insert the View has a custom field value then you could use that to provide the attribute value (e.g. in my example I would insert a shortcode to output the field to provide the value of wpvstatus in my wpv-view shortcode), or in the View you can output that custom field belonging to the page where you insert the View by specifying that in the post selection when you insert the field (screenshot), which will add an item="$current_page" attribute.

Does that cover what you mean? I wasn't sure what you are asking.

#1211216
Screenshot 2019-03-07 at 11.24.41.png

Hi Nigel,

It is quite hard to explain.

I have attached a screenshot to show you what I mean I think this will be much clearer.

From the screenshot you can see where I want to use the variable but it wont work and where it would work but I don't want it there as it would then repeat.

Cheers.

#1211263

Nigel
Supporter

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

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

Right, well inside the loop the shortcode is taking the current post being iterated over as the source for the custom field.

Where you have it, outside the loop, there is no current post (or rather, the "current" post would be the page where you have inserted the View), so what should the shortcode treat as the source for the custom field?

Custom fields belong to posts, so which post should it be getting the value from?

#1211427

Yeah I do get why it doesn't work to be fair, I was curious if there was a way to get it to work though?

All the results will have the same value for this custom field due to the custom field filter on this view.

So it doesn't matter which post they take it from the 1st result is fine.

Is there a way to do this? 🙂

Cheers

#1211429

Nigel
Supporter

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

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

Well it looks like you are passing the field value through a brand shortcode attribute, that's where the filter value comes from, right?

Which just takes me back to what I said before. You output the value of that shortcode attribute using the wpv-attribute shortcode: https://toolset.com/forums/topic/is-it-possible-to-set-the-custom-field-data-to-be-queries-in-the-view/#post-1211142

#1211504

AH, got it. Confused me at first but figured it out. Cheers. 🙂