Skip Navigation

[Resolved] View conditional not working

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

Problem:
View conditional not working

Solution:
You can use [wpv-conditional] shortcode to display conditional output and check multiple conditions with same field.

For example:

[wpv-conditional if="( '[wpv-post-field name='wpcf-riposte-to']' gt '0' ) AND ( '[wpv-post-field name='wpcf-riposte-to']' ne '' )"]
      	[wpv-post-body view_template="Loop item in riPOSTe to"]
[/wpv-conditional]

You can find proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/view-conditional-not-working/#post-913379

Relevant Documentation:
=> https://toolset.com/documentation/user-guides/conditional-html-output-in-views/

This support ticket is created 6 years, 7 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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: Asia/Kolkata (GMT+05:30)

This topic contains 6 replies, has 2 voices.

Last updated by WillL606 6 years, 7 months ago.

Assisted by: Minesh.

Author
Posts
#911968

I am trying to:
Related to a previous issue with conditionals on a View. I have a View called "riposte to" which is now working - NOT displaying an essay when no value is set in a custom field. You had given me a script for functions.php to get a list the essays in the dropdown menu custom field and a conditional to show only if an essay is selected in the dropdown using this:

<wpv-loop>
      [wpv-conditional if="( '[wpv-post-field name='wpcf-riposte-to']' ne '0' )"]
        [wpv-post-body view_template="Loop item in riPOSTe to"]
      [/wpv-conditional]
</wpv-loop>

What I have done is replicate the script and and the conditional for two similar Views: "riposte from" and "riposte from other".
These both select essays the are responses (ripostes) about the current essay, whereas the previous "riposte to" selects an essay for which the current essay is response.

I think the problem is that I have not made the proper adjustments to the scripts in the function.php file to replicate the first functionality. Not sure what the number are in the function parameters.

Link to a page where the issue can be seen:
hidden link
This page has no essays selected to any of the three riposte views.

I expected to see:
On this essay, there should be no sidebar riposte views displayed.

Instead, I got:
The three sidebar views are showing with a link to the current essay.

#912364

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - do you mean that there is no entry set for any essay post for both of the fields "riposte from" and "riposte from other" so it should work same as the "riposte to" field - correct?

#912514

Minesh,
On this essay - hidden link for example - there is no entry set for "riposte to", "riposte from" or "riposte from other" and yet on the right sidebar it is displaying all three of these Views with a link to itself. There should be nothing displayed.

Another essay, for example - hidden link - is only a "riposte to" another essay. Only this field is set, and yet it is also displaying "riposte from" itself. It should only display "riposte to".

I think the issue must be in how I have copied and adjusted the filters:

// to display ripostes that essay is to

add_filter( 'wpv_filter_query', 'func_display_current_essay_post', 10, 3 );
function func_display_current_essay_post( $query_args, $view_settings, $view_id ) {
    global $post;
	
    if ($view_id == 5197) { 
      $query_args['post__in'] = array($post->ID);

    }
 
    return $query_args;
}

// to display riposte about

add_filter( 'wpv_filter_query', 'func_display_current_essay_post_from', 10, 3 );
function func_display_current_essay_post_from( $query_args, $view_settings, $view_id ) {
    global $post;
	
    if ($view_id == 5199) { 
      $query_args['post__in'] = array($post->ID);

    }
 
    return $query_args;
}


// to display another riposte about

add_filter( 'wpv_filter_query', 'func_display_current_essay_post_other_from', 10, 3 );
function func_display_current_essay_post_other_from( $query_args, $view_settings, $view_id ) {
    global $post;
	
    if ($view_id == 5272) { 
      $query_args['post__in'] = array($post->ID);

    }
 
    return $query_args;
}

#912802

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - that was happening because you did not updated the Essay entry as we added those custom fileds after you created the essay entry. It will not have any issue with newly created entries.

As you can see with the link - its showing correct output: hidden link

Now - what I suggest to test this is test by creating new essay entry and for existing essay entry just click on update button once.

Another issue was you were using wrong field name with view "riPOSTe from other":
=> hidden link

I've corrected the filed name for above view as given under:

<wpv-loop>
    
      [wpv-conditional if="( '[wpv-post-field name='wpcf-another-riposte-from']' ne '0' )"]
		[wpv-post-body view_template="loop-item-in-riposte-from-other"]
      [/wpv-conditional]
	</wpv-loop>

I can see now everything is working fine. could you please confirm.

#913137

Thanks Minesh,
These changes have fixed some of the problems. But the big one I am noticing since these changes is that ALL essays that have not been updated are getting these fields populated with links to itself. I can see that these go away when the essays are update, but that means going back to each essay - there are over 900 essays. I don't think this was happening before. That is, essays without these fields selected did not show anything in the sidebar.

Is there a solution to this? As I said, those essays that are updated are working fine.

#913379

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Ok - to overcome that issue - Logically we need to check that if field has any value and if it has any values that should be greater than 0.

I've adjusted all of your views:
=> hidden link
=> hidden link
=> hidden link

If you will check the loop output section - you will see the adjusted [wpv-conditional] shortcode with AND condition. could you please check and confirm it works for you now for all of your posts.

#913559

Thank you, Minesh. I appreciate your help with all of this.