Skip Navigation

[Resolved] Can’t use a custom field as a variable for a filter. Or can I?

This thread is resolved. Here is a description of the problem and solution.

This support ticket is created 6 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 14 replies, has 2 voices.

Last updated by Oscar 6 years, 8 months ago.

Assisted by: Minesh.

Author
Posts
#864033

Tell us what you are trying to do?
I have 2 CPT's with no official parent-child relationship.

Think of them as persons and videos. The Videos CPT has fields for persons involved in the video and we put those into individual single line fields where the numberic post id from the person CPT goes into.

We have a layout where we can display any information about the Person CPT. We now want to add a cell in the layout where we can call in any videos that have the "person-involved-field" match the current Person CPT post id.

I've tried a few different ways, but I can't make the postid match to the person-involved-field. I saw your documentation and it seems the only way I can do this is by calling the person-involved-id as a url paramerter, but I don't want to use that.

Is there a way to create a view or search query based on the variable... set in a custom field in another custom post type?

Basically in a a layout where I show mostly fields set for that specific custom post type, I'd like to do some sort of additional loop like this:

display any video cpt where the person-involved field matches the current post id.

Is there any documentation that you are following?
I have tried to follow your documentation on filtering and querying but can't quite figure this out.

Is there a similar example that we can see?
I don't know...

What is the link to your site?
* It's behind a maintenance plugin, but I can unlock whatever you need to look at it.

#864747

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - As you said, you would not like to pass the post ID as URL param, what if you pass the post ID as view's shortcode attribute instead and filter your view by shortcode attribute.

For example:

[wpv-view name="view-name" postid="999"]

Where:
- postid is a view's shortcode attribute that contains the value of your desired post id. I set it static for now to 999 - you can change it as per your need.

And set your view to filter to filter by shortcode attribute.

More info:
=> https://toolset.com/documentation/user-guides/passing-arguments-to-views/#controlling-the-filter-with-shortcode-attributes
=> https://toolset.com/documentation/user-guides/filtering-views-by-custom-fields/#source-for-compare-value

Please feel free to get in touch with me, with your queries, if any.

#872621

Okay. I think I understand what you're saying. I'm going to give it a try and get back to you.

#872622

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Ok fine - thank you. Please feel free to get in touch with me if you need further assistance.

#872656

Hi Minesh, I re-reviewed your suggestion and re-read the documents. I had seen them before and I tried following them. I'm going to try them again... but are you saying that I can use the variable/shortcode/slug of the postid field instead of your 999 constant? -- I thought I tried that and it didn't work. but I'll try it again.

#872753

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Yes - try the shortcode that return the value of your field.

If you still have issue, send me problem URL with access details and your expected output.

#872764

Yes, I probably will need more help. This is what I've done so far...

1 - created a basic "videos" view.

2 - went in to add a new cell to my single-view-layout for "persons"
2a. the cell calls for the view I created in step 1.
2b. I went to filter and I'm stuck there.

What exactly goes into the shortcode attribute? The "shortcode" for the post-id field? or the slug? -- I need that value to be dynamic based on the single-view-layout, or rather when it gets called. I can't use the slug, or the post-field shortcode...

screenshot -- hidden link

#872770

Hi, how do I send you the details? I don't want to post them publicly...

Thanks.

#872871

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

[wpv-view name="view-name" postid="999"]

Referring to above example, please let me know which field value you want to replace with 999 value and please share problem URL where you added the view and view name.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).

I have set the next reply to private which means only you and I have access to it.

#873017

I added some details to the private message, including a short 4 min video showing you. I think it'll explain better.

#875363

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

I believe you do not understand how to filter by shortcode attribute that I tried to explain in my previous reply here:
=> https://toolset.com/forums/topic/cant-use-a-custom-field-as-a-variable-for-a-filter-or-can-i/#post-864747

Additionally, I know its how-to question not a troubleshooting one but we send such message so you know that we may make changes to your setup. Its just for keep you notified ?

I have make amendments according to your requirement. what I've done is added the view to your layout using Visual Editor cell as given under:

[wpv-view name="mini-video-view-for-videos-by-character" pid="[wpv-post-id]"]

Where:
- As you can see pid holds the current post ID value and it will work dynamically.

Then, I've change the filter in your view to filter it using shortcode attribute "pid". As you can see with this screenshot:
=> hidden link

I can see its working fine now. Could you please confirm. ?

#876657

Brilliant! Exactly what I needed.

And you're right, I didn't understand. It's still a little fuzzy, but I see what you did.

So a follow-up question. "pid" as you used it in the shortcode attribute, that's an arbitrary thing you came up with right? I mean the value there could have been "anything" as long as I call it as the filter later on correct?

But yes, this is working exactly as I wanted it. And I can use this for other scenarios. Thank you.

I know the standard disclaimer, but I wanted to give you my disclaimer. Obviously, you know what you're doing, but I've had other cases with other companies where the tech support isn't as knowledgeable and careful as you are.

#876658

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

So a follow-up question. "pid" as you used it in the shortcode attribute, that's an arbitrary thing you came up with right? I mean the value there could have been "anything" as long as I call it as the filter later on correct?
==> "pid" is shortcode attribute name - yes, you can give it as "postid" or "customfieldvalue" anything but you need to make sure the same name should be used when you add Query filter as it displayed in this screenshot:
=> hidden link

Thanks for your feedback. You are free to share your feedback. Have a great weekend.

#876676

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Could you please mark this resolved. Have a great weekend 🙂

#878173

Thank you. Closed!