Skip Navigation

[Resolved] A code that works on it's own does not display when looped in a view

This support ticket is created 3 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.

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.

This topic contains 1 reply, has 1 voice.

Last updated by AlimB3245 3 years, 7 months ago.

Author
Posts
#1782611

Tell us what you are trying to do?

I have code based on this ticket.. https://toolset.com/forums/topic/display-field-values-from-related-grand-parent-post/#post-1782239

you will see that the code that's used there is working well when displaying value on a page..

[wpv-post-body item="@eyewear-brand-eyewear-collection.parent" view_template="brand-distributor-id-for-eyewear-collections"]

I need to display the same code but with a condition so I used a view and am trying to run the condition from a shortcode and if the condition is met then display the code

[wpv-layout-start][wpv-items-found]<!-- wpv-loop-start --><wpv-loop>[wpv-item index=other][wpv-conditional if="( '[check-user-store-value]' eq '1' )" ][wpv-post-body item="@eyewear-brand-eyewear-collection.parent" view_template="brand-distributor-id-for-eyewear-collections"][/wpv-conditional]</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]

the check-user-store-value shortcode is here.. it just checks if the user-store and the eyewear-store match and it's working fine..

function func_check_user_store_value() 
{
	global $current_user;
    
	$eyewear_store_value = do_shortcode("[types field='eyewear-store' output='raw' item='@brand-distributor-eyewear-brand.intermediary'][/types]");
	$user_store = do_shortcode("[types usermeta='user-store' output='raw' current_user='true'][/types]");
  
	if(strpos($eyewear_store_value, $user_store) !== false)
	{
		return 1;
	} 
	else 
	{
		return 0;
	}
  
}

add_shortcode( 'check-user-store-value', 'func_check_user_store_value' );

Even though the condition works fine and it displays the content of the template (I've tested it by using some static content), for some reason either the 'item=@eyewear-brand-eyewear-collection.parent' and the contents below from the view template don't seem to work when within the loop.

[types field="id" item="@brand-distributor-eyewear-brand.parent"][/types]

you would need to log in with credentials as an optician here hidden link to view the result

Please advise what am I doing wrong?

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site? hidden link

#1782827

My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.