Skip Navigation

[Resolved] Back link not showing

This support ticket is created 4 years, 3 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: Asia/Karachi (GMT+05:00)

This topic contains 4 replies, has 2 voices.

Last updated by shaunV 4 years, 3 months ago.

Assisted by: Waqar.

Author
Posts
#1744931

I have a CPT called Shop, a custom repeatable group called Shop-social-links. I have created cred_child_link_form from my shop single post to a content template displaying my form and a view, so people can see the what is in the repeatable group. All good until here. My problem is that I am having a really hard time displaying a button back to my shop single post. I have used the following but not had much luck. [wpv-post-url item=" @shop-social-links.parent"]

hidden link

Interestingly it works in the backend when inside the view, but does not display on the front end.

#1745371

Hi,

Thank you for waiting.

I noticed that ID of the source shop single post is available in the URL parameter "parent_store_id".

You can get this value using the "wpv-search-term" shortcode:
( ref: https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#wpv-search-term )


[wpv-search-term param='parent_store_id']

And you can use it in your back button's code like this:


<a href="[wpv-post-url item='[wpv-search-term param='parent_store_id']']" class="btn btn-primary"> ⇽ Go back to product</a>

The same shortcode can also be used for checking whether some value for the "parent_store_id" URL parameter is set or not.
( ref: https://toolset.com/documentation/user-guides/views/conditional-html-output-in-views/using-shortcodes-in-conditions/ )

Example:


[wpv-conditional if="( '[wpv-search-term param='parent_store_id']' ne '' )"]
// Some value is set for the "parent_store_id" URL parameter
[/wpv-conditional]

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

regards,
Waqar

#1745773

Thank you sir, that works fine.

As per the conditional, other users with same role can manually visit and add to the form.
A "solution" is to nest conditional values with a shortcode inside, but of course that won't work:

  ( ( '[wpv-post-author format="meta" meta="ID" id="[wpv-search-term param='parent_store_id']"]' = '' ) ) 

Any ideas on how achieve this?
I have also tried @shop-social-links.parent, but I feel like the relationship between my post type Shop and the repeatable group is not set up as a parent-child relationship.

#1746301

Thanks for the update and glad that it works.

If I understand correctly, you'd like to extend the conditional check to also see if the current user is also the author of the shop post where the user has come from.

If that's the case, you'll need a custom shortcode, that can check for both these conditions and then return 0 or 1 accordingly.
( a custom shortcode is needed as the conditions with nested shortcode attributes would become too complex in this case )


add_shortcode('check_complex_condition', 'check_complex_condition_fn');
function check_complex_condition_fn() {
	if( (isset($_GET['parent_store_id'])) && (!empty($_GET['parent_store_id'])) ) {
		$current_user_id = do_shortcode("[wpv-user field='ID']");
		$current_shop_author_id = do_shortcode("[wpv-post-author format='meta' meta='ID' item='".$_GET['parent_store_id']."']");
		if($current_user_id == $current_shop_author_id) {
			return 1;
		} else {
			return 0;
		}
	} else {
		return 0;
	}	
}

This shortcode will return "1" only if some "parent_store_id" URL parameter value is set and the current user is also the author of the shop post and otherwise it will return "0".

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 active theme's "functions.php" file.

Next, please also add "check_complex_condition" in the "Third-party shortcode arguments" section, at WP Admin -> Toolset -> Settings -> Front-end Content.

After that, you can use this shortcode in a condition, simply like this:


[wpv-conditional if="( '[check_complex_condition]' eq '1')"]
// The current user is the author of the store and some value is set for the "parent_store_id" URL parameter and the
[/wpv-conditional]

As for the item attribute's format "@shop-social-links.parent" or "@shop-social-links.child", it will only work when the current post's scope is either a single social-links post or a single shop post, respectively.
( ref: https://toolset.com/documentation/programmer-reference/views/views-shortcodes/item-attribute/ )

But, the page "yourwebsite.com/add-social/" is none of those.

#1749071

You guys are awesome, the function works great.

The only problem I encountered was that it did not want to save using while using the Snippets plugin nor with Toolset/Settings/Custom Code (Toolset prompts:" There was an error when updating snippets."

So I added it to my theme functions and that worked. Any chance you know what the cause may be? I tried renaming the function and changing the shortcode. I also checked with multiple php checkers online if there were any errors, and did not find any.

Thank you!!