Tell us what you are trying to do?
I'm trying to list posts with the same value for a particular custom field as the current post
Is there any documentation that you are following?
https://toolset.com/documentation/user-guides/views/passing-arguments-to-views/#controlling-the-filter-with-shortcode-attributes
Is there a similar example that we can see?
I've set up the query filter of the view to use custom field filter, as shown in uploaded image, I've used shortcode attribute 'birthdate'
when calling up the view in my template using block editor, how to i pass the argument to the view?
What is the link to your site?
hidden link
Hello and thank you for contacting the Toolset support.
As of now, it is not possible to pass arguments to views from a block in such similar way described in this article https://toolset.com/documentation/user-guides/views/passing-arguments-to-views/#controlling-the-filter-with-shortcode-attributes
Depending on your use case, you can use a classic block and then use the view shortcode inside it, or you will need to use a hybrid approach between blocks and views to perform that. This may also need an unassigned content template to hold the post context and then pass it to the view.
Can you give more details on your use case and I'll try it locally to check what could be done with blocks and views?
Can you also paste your Toolset Debug information in the Debug information field?
- https://toolset.com/faq/provide-debug-information-faster-support/
Hi Jamal,
thank you for your suggestions.
"use a hybrid approach between blocks and views to perform that. This may also need an unassigned content template to hold the post context and then pass it to the view."
I did that for another section on the same page. maybe i can do the same, but that was a parent template displaying child posts, any suggestion on how to pass the value of a custom field of the current post to the view as a filter?
my use case:
current post has custom fields, one of which is 'date-of-birth'
i want to list all others with the same 'date-of-birth'
Dave
Hello Dave,
I am still not sure if you want to show the current post in a single post page or inside a loop(archive, view)! So I run a test locally and I was able to display the posts that have a similar date of birth in a single post page and in a view of posts.
Basically, the idea is to use a "Field and Text" block or a "Classic" block to pass the argument to the view with a shortcode.
I run my tests on regular posts types with a field group(Posts Birth Field Group) and a custom field date-of-birth.
1. I created a view(Same Date of Birth), I did not use blocks here, but I think that we can. This view will display the posts with similar date-of-birth. We will pass the date-of-birth using a shortcode attribute. Check this section https://toolset.com/documentation/user-guides/views/passing-arguments-to-views/#filters-by-custom-fields
Check the view query filter in this screenshot hidden link
The Date of birth field should be a number and equal to the value of the shortcode attribute "dateofbirth".
2. Then, I created an unassigned content template. This content template will hold the context(post) and pass its date-of-birth to the view created in (1).
The content template is created with blocks, and I used a "Fields and Text" block to use the view and pass the date-of-birth to it as an attribute. In the HTML mode of the block I added the following shortcodes:
[wpv-view name="same-date-of-birth" dateofbirth="[types field='date-of-birth' output='raw'][/types]"]
Note that the date of birth should be a timestamp and not a formatted date. You can choose that if you use the "Add Field or View" button on the "Fields and Text" block.
3. Use the unassigned content template(created in (2)) inside a block. In my test, I updated 3 posts from the "world" category with date-of-birth to verify.
- Either on a view. In my test, I created a page, and inserted a view block, created a new view that shows posts from the "world" category. Inside the loop, I used the unassigned content template.
- On a single post. In my test, I edited a post from the "world" category and used the unassigned template to show it.
I hope this helps. Let me know if you have any doubts.
Hi Jamal,
Thank you for the suggestion. I am using a single post page for display. It worked out well.
With this approach, what if I wanted to pass 2 arguments?
not necessarily 2 arguments, but together with the method I wanted to also filter with post relationships.
Do you want me to mark this as resolved and open a new ticket?
thanks
Dave
Hello Dave,
Well, for passing two arguments, you can do the same method/technique. But If you would like to filter by relationship, I would suggest marking this ticket as resolved and creating a new ticket. Please provide as many details about your relationship and on the page that you would like to create to get fast support.
Best regards,
Jamal
My issue is resolved now. Thank you!
Will this feature be supported in the block somewhen?