Skip Navigation

[Resolved] Conditional Logic Help (with 1 custom USER field and 1 custom post type field)

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.

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: Asia/Karachi (GMT+05:00)

This topic contains 2 replies, has 2 voices.

Last updated by Bobby339 11 months ago.

Assisted by: Waqar.

Author
Posts
#2613511

Hello! I am trying to make a button appear to add more items if the user has NOT gone over their allocated number of X (where X is a custom post type) but if they have hit that amount, a message will appear telling them why the button is gone.

I have a VIEW that outputs the number of X this user has created (and it works great):
[wpv-view name="myexpactivecount" user="[wpv-user field='ID']"]

Each user has a custom USER field where I can enter a number of the total amount of X I want this user to be able to create, this shortcode outputs that number perfectly:
[types usermeta='usertotalexperiences' output='raw' current_user='true']

So I can output something like this:
<small>You are using [wpv-view name="myexpactivecount" user="[wpv-user field='ID']"] out of [types usermeta='usertotalexperiences' output='raw' current_user='true'] of your available Experiences</small><br>

And it looks great!

However, when I use those variables in two conditional logic statement, it does not work 🙁

Below is the conditional logic I have (that does not work), can you tell me why it does not work and help me fix it?

[wpv-conditional if="( '[wpv-view name='myexpactivecount' user='[wpv-user field='ID']' lt '[types usermeta='usertotalexperiences' output='raw' current_user='true']' )"]BUTTON APPEARS HERE[/wpv-conditional]

[wpv-conditional if="( '[wpv-view name='myexpactivecount' user='[wpv-user field='ID']' eq '[types usermeta='usertotalexperiences' output='raw' current_user='true']' )"]MESSAGE ANOUT WHY NO BUTTON APPEARS[/wpv-conditional]

#2613903

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting us and I'd be happy to assist.

The 3 levels of nesting of shortcodes in the conditional setup that you're using, make it difficult to be recognized by the system.

You can register a custom shortcode, that can process the shortcode for the view ( i.e. [wpv-view name="myexpactivecount" user="[wpv-user field='ID']"] ) and return the output, as a single-level shortcode.

For example:


add_shortcode('myexpactivecount', 'myexpactivecount_fn');
function myexpactivecount_fn() {
	// get current user ID
	$user_id = do_shortcode("[wpv-user field='ID']");
	// generate output from the view's shortcode
	$content = do_shortcode("[wpv-view name='myexpactivecount' user='".$user_id."']");
	return $content;
}

The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.

Also, add "myexpactivecount" in the "Third-party shortcode arguments" section, at WP Admin -> Toolset -> Settings -> Front-end Content.

After that, you can use this new custom shortcode in the conditional statements like this:


[wpv-conditional if="( '[myexpactivecount]' lt '[types usermeta='usertotalexperiences' output='raw' current_user='true']' )"]
BUTTON APPEARS HERE
[/wpv-conditional]

[wpv-conditional if="( '[myexpactivecount]' eq '[types usermeta='usertotalexperiences' output='raw' current_user='true']' )"]
MESSAGE ABOUT WHY NO BUTTON APPEARS
[/wpv-conditional]

I hope this helps and please let me know if you need further assistance.

regards,
Waqar

#2613929

OMG! Thank you so much for the detailed reply, it worked great! Toolset support is AMAZING (and has been for years)!

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.