Skip Navigation

[Resolved] Support on development V2

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

Problem:
The user is following this tutorial to create a comparison page https://www.youtube.com/watch?v=oSuY4QF812s
When he selects more than 2 posts, the view works as expected. When he selected one post or none, the view displays all the posts.

Solution:
We'll need to implement a custom code that will check how many posts are passed to the comparison page. Then we can conditionally display the comparison view or a message.
This a sample code for the shortcode:

add_shortcode( 'compared-post-ids-count', 'compared_post_ids_count_func' );
function compared_post_ids_count_func () {
  $post_ids = isset( $_GET['post_ids'] ) ? $_GET['post_ids'] : array();
  return sizeof( $post_ids );
}

The shortcode needs to be registered in Toolset->Settings->Front-end Content to be used in conditions.

Then we can display a view or a message, like this:

[wpv-conditional if="( [wpv-search-term param='post_ids'] ne '' )"][wpv-view name="scholen-vergelijken-po"][/wpv-conditional]
 
[wpv-conditional if="( [wpv-search-term param='post_ids'] ne '' )" evaluate="false"]You will need to select at least two posts to compare[/wpv-conditional]

Relevant Documentation:
https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/using-shortcodes-in-conditions/

This support ticket is created 4 years, 4 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
9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 - - 9: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: Africa/Casablanca (GMT+01:00)

This topic contains 7 replies, has 2 voices.

Last updated by richardd-6 4 years, 4 months ago.

Assisted by: Jamal.

Author
Posts
#1779169

Hi,
I am replying to: [Resolved] Support on development – comparison table #1771227
#2
I added the condition with wpv-search-term but the output is not good. You can see it on hidden link? But i don't get this to work. What am I doing wrong?
The code below is in the loop editor.

[wpv-conditional if="( '[wpv-search-term]' ne '0' )"]
[wpv-layout-start]
<div class="container">
<div class="row">
<div class="col bg-light mr-2 pt-4">Hier opbouwen</div>
[wpv-items-found]
<!-- wpv-loop-start -->
<wpv-loop wrap="4" pad="true">
[wpv-item index=1]
<div class="col bg-light mr-2 pt-4">[wpv-post-body view_template="loop-item-in-scholen-vergelijken"]</div>
[wpv-item index=other]
<div class="col bg-light mr-2 pt-4">[wpv-post-body view_template="loop-item-in-scholen-vergelijken"]</div>
[wpv-item index=4]
<div class="col bg-light mr-2 pt-4">[wpv-post-body view_template="loop-item-in-scholen-vergelijken"]</div>

</wpv-loop>
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-no-items-found]
[wpml-string context="wpv-views"]No items found[/wpml-string]
[/wpv-no-items-found]
</div>
</div>
[wpv-layout-end]
[/wpv-conditional]

Furthermore i moved the website from local to a live website, only the markers on hidden link aren't working anymore. Only the first 5 results show. I tried a new maps api key, empty wordpress cache, Toolset cache, make a new map, but I don't get this to work. Can you help me?

Thanks in advance.
Cheers Richard

#1780179

Hello Richard,

Currently, you are putting the conditional shortcodes inside of the view. What I suggested, is to put the conditional shortcode in the page where the view will be used. Then if the condition is met, the view will display, otherwise, the view will not be executed at all.

So, your page will have the following code:

[wpv-conditional if="( '[wpv-search-term]' ne '0' )"]
  [wpv-view name="My comparaison view"]
[/wpv-conditional]

I hope this makes sense! Let me know if you have any questions.

#1780211

Hi Jamal,
Now I did exactly what you suggested, but nothing happens.

#1780225

Please allow me temporary access to check this closely. Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **

Please provide the required details:
- What page is used to display posts and select them for comparison.
- What page is used for the comparison details.

#1780325

Thank you for the credentials. Please check the comparison page here hidden link

I added two conditional shortcodes, the first evaluates to true and displays the view, the second evaluates to false and display a message instead. Check this screenshot hidden link
This is the code:

[wpv-conditional if="( [wpv-search-term param='post_ids'] ne '' )"][wpv-view name="scholen-vergelijken-po"][/wpv-conditional]

[wpv-conditional if="( [wpv-search-term param='post_ids'] ne '' )" evaluate="false"]You will need to select at least two posts to compare[/wpv-conditional]

I hope this helps. Let me know if you have any questions.

#1780405

Hi Jamal,
When i select 1, I see all items.
If i select 2 or more I don't see the results, only the message: You will need to select at least two posts to compare.
Is it posible to display the message with 0 or 1 selected and results with >2?

Furthermore i moved the website from local to a live website, only the markers on hidden link aren't working anymore. Only the first 5 results show. I tried a new maps api key, empty wordpress cache, Toolset cache, make a new map, but I don't get this to work. Can you help me?

#1781349

For that we'll need to implement a custom function or a custom shortcode that will count the post_ids, then we can use it in the conditional shortcode.

I implemented a shortcode compared-post-ids-count, you can check it at Toolset->Settings->Custom Code. Then I registered the shortcode to be used inside conditionals in Toolset->Settings->Front-end Content->Third-party shortcode arguments.

add_shortcode( 'compared-post-ids-count', 'compared_post_ids_count_func' );
function compared_post_ids_count_func () {
  $post_ids = isset( $_GET['post_ids'] ) ? $_GET['post_ids'] : array();
  return sizeof( $post_ids );
}

Then I used it as follow:

[wpv-conditional if="( [compared-post-ids-count] gt '1' )"][wpv-view name="scholen-vergelijken-po"][/wpv-conditional]
[wpv-conditional if="( [compared-post-ids-count] gt '1' )" evaluate="false"]You will need to select at least two posts to compare[/wpv-conditional]

But, I am not sure, because of the language barrier, if I did break the page(when more than 1 product is selected). Can you double-check and get back to me?

#1781467

My issue is resolved now. Thank you!