Skip Navigation

[Résolu] Conditional output stoped working

This support ticket is created Il y a 6 années et 3 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.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

Ce sujet contient 2 réponses, a 2 voix.

Dernière mise à jour par davidZ-4 Il y a 6 années et 3 mois.

Assisté par: Nigel.

Auteur
Publications
#1088200

I am trying to: display posts (non protected) in a view

Link to a page where the issue can be seen: lien caché

I expected to see: non protected posts on the page

Instead, I got: no results at all

i use the fallowing in my view loop output editor:

 <wpv-loop>
            [wpv-conditional if="( '[is-protected]' ne '1' )"] <div class="col-sm-4">
      
      [wpv-post-body view_template="Memorials list for search"]</div>[/wpv-conditional]
    </wpv-loop>

it use to work in the past and now for some reason now it doesn't. i don't recall any updates i made recently.
when i remove the conditional output i get all the results on the page but with protected posts (that i want to hide)

 <wpv-loop>
           <div class="col-sm-4">
      [wpv-post-body view_template="Memorials list for search"]</div>
    </wpv-loop>

i have created and registered the shortcode [is-protected] as instructed here https://toolset.com/forums/topic/omit-private-posts-from-view-via-filter/#post-367945

please advise, how i can hide the protected custom posts from the view.
thanks,

David

#1088372

Nigel
Supporter

Les langues: Anglais (English ) Espagnol (Español )

Fuseau horaire: Europe/London (GMT+00:00)

Hi David

I don't know what's in your custom shortcode, but in any case a better solution is to use the wpv_filter_query filter so that the query doesn't return any protected posts in the first place.

(Your solution means running the conditional check for every iteration of the results.)

You can do that with the following code:

function tssupp_omit_protected_posts( $view_args, $view_settings, $view_id ){

	if ( in_array( $view_id, array( 204 ) ) ) { //Edit for IDs of Views

		$view_args['post_password'] = '';
	}

	return $view_args;
}
add_filter( 'wpv_filter_query', 'tssupp_omit_protected_posts', 101, 3 );
#1090493

Hi Nigel,
When I tried your code on the site it didn't work.
I do see why it make sense to use the approach you suggested and I will give it another shot later on.
the way I solved the issue was to update WP, theme, and all plugins. it did the trick and everything is working as it was designed for. I hope this close the issue...

Thanks for the help.
David