Hi Support team,
I have CPT called "destinations". On the destination template i am showing destination-ads(many). This is a post type that is the child of destination (1). The view I created on the template for the destinations CPT shows the destination-add based on the relationship between them. The destination-ad CPT also has an other parent CPT called company. In the view I show the logo of this company and the deeplink from the destination-ad CPT. So far so good. I am using blocks to create the template.
Example of the destination template (slug-= rondreis) with the ads on the bottom:
hidden link
For maintenance purposes I want to be able to show or hide all the destination-ads of a specific company. I have added an extra custom field to the CPT companies called "active". I now only want to display the destination ads where the custom field of the parent (companies) has the value active.
Can you please help me how to achieve the filtering of this view for this value.
Thank you,
Kind regards
Edwin
Hello,
In your case, you can try these:
1) in a single "destination-ads" post, you can display it's parent "active" field value with Types shortcode, for example:
[types field="my-field" item="$companies-destination-ads.parent"][/types]
Please replace "my-field" with your "active" field slug,
replace "companies-destination-ads" with your post type relationship slug between "companies" and "destination-ads"
2) Then use above shortcode in [wpv-conditional] shortcode to check if it is activated, then display the "destination-ads" post information, for example:
[wpv-conditional if="( '[types field="my-field" item="$companies-destination-ads.parent"][/types]' eq 'activated' )"]
... display the "destination-ads" post information ...
[/wpv-conditional]
Please replace "activated" with the "active" field value
More help:
https://toolset.com/documentation/user-guides/views/views-shortcodes/item-attribute/
https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/using-shortcodes-in-conditions/
Hi Luo,
Thank you. I think I got the first part of the answer covered. I already retrieve the data from the parent (companies) of destination-ads(child of companies and destination) on the destination page(parent of destination ads). I have added an extra view for testting purposes on the bottom of the page which shows the logo(custom field from CPT Company), URL (Custom field from CPT destination-ads) and the "active" field value ( Checkbox from CPT companies). It looks like this
[wpv-post-title]
[types field='logo' title='%%TITLE%%' alt='%%ALT%%' size='full' item='@reisorganisatie-robestemming.parent'][/types]
[types field="deeplink-bestemming"][/types]
[types field="actief" item='@reisorganisatie-robestemming.parent'][/types]
reisorganisatie stands for "Companies" and robestemming for "destination-ad"
The result is the row at the bottom of the page hidden link (exemple of destination CPT)
I have added the following code in the loop editor and experimented with placing it on different places. The result should be that I only see the first 2 ads (seen from the left) with the active "1" value on hidden link
But it does not filterthe output of destinatio ads.
[wpv-conditional if="( '[types field="actief" item='@reisorganisatie-robestemming.parent"][/types]' eq '1' )"]
... display the "destination-ads" post information ...
[/wpv-conditional]
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop wrap="6" pad="true">
[wpv-item index=1]
<div class="row ">
<div class="col-sm-2">[wpv-post-body view_template="loop-item-in-filterro"]</div>
[wpv-item index=other]
<div class="col-sm-2">[wpv-post-body view_template="loop-item-in-filterro"]</div>
[wpv-item index=6]
<div class="col-sm-2">[wpv-post-body view_template="loop-item-in-filterro"]</div>
</div>
[wpv-item index=pad]
<div class="col-sm-2"></div>
[wpv-item index=pad-last]
<div class="col-sm-2"></div>
</div>
</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
[/wpv-no-items-found]
[wpv-layout-end]
Thank you.
Kind regards,
Edwin
You can use [wpv-conditional] short code within view's loop, for example:
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
<div class="row ">
<wpv-loop>
[wpv-conditional if="( '[types field="actief" item='@reisorganisatie-robestemming.parent"][/types]' eq '1' )"]
<div class="col-sm-2">[wpv-post-body view_template="loop-item-in-filterro"]</div>
[/wpv-conditional]
</wpv-loop>
</div>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
[/wpv-no-items-found]
[wpv-layout-end]
Hi Luo,
Thank you. The loop editor is still a bit difficult for me toe really understand yet. Therefore I have copy-pasted your code and replaced mine. There is no output anymore for the view.
What am i doing wrong?
An other question is that I use Blocks. There does not seem to be a way to pass these condtional output in the block editor when creating a view. Switching to the Classic editor does not seem possible. Is this correct?
What would be a workflow to overcome this?
Kind regards,
Edwin
In block editor, within view's loop, you can add a shortcode block, and display codes:
[wpv-conditional if="( '[types field="actief" item='@reisorganisatie-robestemming.parent"][/types]' eq '1' )"]
<div class="col-sm-2">[wpv-post-body view_template="loop-item-in-filterro"]</div>
[/wpv-conditional]
If you need more assistance for it, please provide a test site with the same problem, fill below private message box with login details, also point out the problem page URL and view URL, I need to test and debug it in a live website. thanks
Thanks for the details, I have done below modifications in your website:
Edit the content template:
hidden link
Change the codes as below:
...
[wpv-conditional if="( '[types field="actief" item="@reisorganisatie-robestemming.parent"][/types]' eq '1' )"]
<div class="col-sm-2">[wpv-post-body view_template="loop-item-in-filterro"]</div>
[/wpv-conditional]
...
Please test again, check if it is fixed, thanks
Hi Luo,
Thank you very much. It works fine. The other part of my question I have not figured out yet.
You said: In block editor, within view's loop, you can add a shortcode block, and display codes:
In the Block editor I still cannot find an area to add the shortcode I have added an image of the Block editor with the first view "FilterRO". opened in the View loop. In none of the sidebar options I can find it. See viewloopsBlocks.jpg image.
Thank you for your great support.
Kind regards,
Edwin
In Block editor, you can try can add shortcodes with shortcode block, see WP document:
https://wordpress.org/support/article/shortcode-block/
If you want to setup wpv-conditional shortcode, you can also try with Toolset conditional block:
https://toolset.com/documentation/user-guides/gutenberg/using-toolset-conditional-block/
My issue is resolved now. Thank you!