This support ticket is created hace 1 año, 5 meses. 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.
Basically, I need to display posts where [wpv-post-taxonomy type="category" format="slug"] equals the current CPT's "[wpv-post-slug]-agenda"
It seems like there should be an easy way to do this.
NOTE: I'm currently working with this in a "classic" view inserted into my content template, but I'd be happy to be able to use the block editor in the content template if it's possible.
Waqar,
I'm having problems with this solution...
Because the conditional (filter) is AFTER the query, I can't limit the desired output correctly. It considers ALL of the non-filtered posts in the limit, so it does not display the correct number of posts for the specific matching category of the conditional.
Example: The query is returning ALL posts where the category ends with "-agenda"
AFTER this, The conditional matches and outputs only posts with "current-page-slug-agenda"
This works perfectly, but I don't want to output hundreds of results on this page, so I've added limit 10
The limit(10) includes: "OTHER-page-slug-agenda" in the limit -- but only displays the ones from the conditional.
So, if there are 9 posts in "OTHER-page-slug-agenda" returned first, my output only displays 1 "current-page-slug-agenda" on the page, instead of 10.
Sadly, I don't think there is any way to make this work - unless there is some way to add the limit directly into the conditional?
Here is an alternate approach for this filtering, which takes place at the query level and not once inside the view (through conditional).
1. You'll need a custom shortcode, that can get the current page's slug and return it, removing the '-agenda' part from it.
(so that slug will match the slug of the term from the 'category' taxonomy)
Next, please add "get_slug_cat_slug_from_page" in the "Third-party shortcode arguments" section, at WP Admin -> Toolset -> Settings -> Front-end Content.
2. Once this shortcode is ready, you can add a taxonomy query filter in your view so that it only shows the results where the slug of the 'category' taxonomy is the same as the value coming from the shortcode attribute 'wpvcategory'.
3. Next, on the page where you'd like to show this view, you can call it through the view's shortcode like this:
[wpv-view name="name of the view" wpvcategory="[get_slug_cat_slug_from_page]"]
As a result, the custom shortcode will provide the slug to limit the results by, depending on the page the view is called.
I hope this helps and please let me know if you need any further assistance with this.
The current page slug does NOT include "-agenda", so I don't need a shortcode to remove/trim it.
I was appending "-agenda" TO the page slug for the conditional filter, so that it would match the taxonomy, which DOES include "-agenda".
I can return the taxonomy, fine... but my template is used for ALL departments, so I was trying to output the posts in the proper taxonomy conditionally based on current page being viewed (page-slug PLUS -agenda matches wpvcategory).
> So the query in my view still needs to return ALL posts, and the wpvcategory="" will then filter those results?
- Yes, that is correct, but this filtering will be taking place as a single step and not as two separate steps, at the query level.
( in simple terms, the query will look like this: 'bring all posts where the category is XYX' )
The count of returned results will not be equal to 'ALL' posts, but only equal to the relevant category's posts, which is what you want.
> Where do I set the limit?
- The number of results returned by the view can be further controlled by the view's "Limit and Offset" settings.
> How is this different from my current code
- Your code or the earlier approach would query ALL posts, and then only limit their display through the conditional display, which was leading to a difference in the number of results.
( because the query would return 'X' amount of results, but then because of the conditional display, only 'Y' amount of results would actually be shown on the front-end, as you noted yourself in your reply: https://toolset.com/forums/topic/output-posts-with-conditional-taxonomy/#post-2507501 )
This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.