This support ticket is created Il y a 4 années et 2 mois. 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.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
I have 6 Pages on the site, each of which are to include a Block that displays a View from my custom post type, with a Taxonomy filter to display only those posts from a certain category.
The slug of the Page and the slug of the Category match. I'm trying to find a way that I can create one single View, to use on all 6 pages, that will correctly display the posts from the corresponding category.
I could build 6 separate views, and use "Categories are any of the following", but didn't know if there would be a way to use "set by the page where this View is shown" or one of the other options, so that I only have one view to manage in the future and to make this more scalable when new pages/categories are added.
Thank you for contacting us and I'd be happy to assist.
To achieve this, you can set the taxonomy filter in the "Query Filter" section to "Set by one View shortcode attribute" option, so that it can read the slug of the target category from the shortcode attribute "wpvcategory".
Thank you! I was trying to use one of the new Toolset Blocks and couldn't find a way to do it.
Going the old-fashioned way with a shortcode, as you suggested, worked great.
I do have one new issue, however. When I place the shortcode on my pages, I get the exact result I'm looking for. But, I tried saving the shortcode block as a Reusable Block, and when I did it returned the following:
<p><!--- View not found --->"]</p>
Perhaps this isn't a Toolset issue, now that we're moving into Reusable Blocks. For now I will just add the shortcode in separate block instances on each page. If this is something that could potentially be set up as a Reusable Block, however, that would be great.
Thanks for the update and glad that the view itself works.
I was able to reproduce the issue with the reusable block when it contains a shortcode within a shortcode. This has been shared with the concerned team for further review and I'll keep you updated on it, through this ticket.
For now, a workaround can be to create a custom shortcode that processes this nested shortcode and then returns its output.
Example:
add_shortcode( 'show_output_taxonomy_view', 'show_output_taxonomy_view_func');
function show_output_taxonomy_view_func() {
// get the page slug
$page_slug = do_shortcode("[wpv-post-slug]");
// output of the view with page slug as the attribute
$view_output = do_shortcode('[wpv-view name="slug-of-the-view" wpvcategory="'.$page_slug.'"]');
return $view_output;
}
Waqar, thanks again. Glad to know that the shortcode-within-a-shortcode issue when placed in a Reusable Block is being addressed.
In the meantime, your suggestion to combine the nested shortcodes into a single shortcode via a function worked exactly as you said.
I now have this implemented, and should there be a new Product to add in the future, the client can just create a new Page and then create a new Category in the custom post type using the same slug, and then insert the resuable block.
I've received an update from the development team and this limitation of using shortcode-within-a-shortcode in reusable blocks is not specific to Toolset plugins.