Skip Navigation

[Resolved] correct syntax for shortcode within shortcode

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

Problem:

The issue here is that the customer had a custom shortcode that he was passing to views as a shortcode parameter but the shortcode doesn't filter the view.

Solution:

In order for custom shortcodes to work here they would need to be added to our views 3rd party shortcode arguments.

This can be found in Toolset->Settings->Frontend and you just need to add the name of the shortcode and it should start working.

This support ticket is created 6 years 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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 5 replies, has 2 voices.

Last updated by MikeT458 6 years ago.

Assisted by: Shane.

Author
Posts
#727486
view def screen shot 2.jpg
view def screen shot 1.jpg
result screen shot.jpg
screen shot source.jpg

I am trying to: pass an argument to a view via a shortcode

Link to a page where the issue can be seen: n/a

I expected to see: see the attached screen shots

Instead, I got: see the attached screen shots
There are 3 lines in the test page. The first calls a shortcode and returns the correct value. The second calls the shortcode with a hard-coded value and the view properly displays. The third line attempts to call the view using the embedded shortcode and the output is incorrect. Here is the source code for the shortcode:

//***************************************************************
// return current supervisor based on current user
//***************************************************************
function sbf_return_current_supervisor() {
  $user_id = get_current_user_id();
  $key = 'wpcf-supervisor-details-post-id';
  $single = true;
  $result = get_user_meta( $user_id, $key, $single );
  if($result) {return $result;} else {return -9999;}
} // sbf_return_current_supervisor
add_shortcode( 'sbf_return_current_supervisor', 'sbf_return_current_supervisor' );

I have enclosed screen shots of the view definition.

Thanks for any help. If there is a better way to accomplish this, please feel free to suggest. This type routine/fi;ter will be used in many views throughout the application. There are many CPT's and a supervisor should only be able to see and/or edit records that are assigned to him/her.

#728721

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Mike,

Thank you for contacting our support forum.

The issue here seems to be a quotation mismatch.

The correct format should be:

[myshortcode param="[mynextshortcode id='4']"]

Notice for the param inside the second shortcode i use single quotes instead of double quotes. This is the correct format.

Please let me know if this helps.
Thanks,
Shane

#731093

Sorry, I think you misread the problem. This line works:

[wpv-view name="my-team-members" supervisor="180"]

This is the line I am asking about:

[wpv-view name="my-team-members" supervisor='[sbf_return_current_supervisor]']

Note that I changed it to single quotes, which changed the output to: ‘] instead of "].

#731094

Addendum to previous post: I took a look at the source and the incorrect output looks like part of an error message that says "View not found". Hope this helps.

	<div class="inside-article">
		
			<header class="entry-header">
				<h1 class="entry-title" itemprop="headline">Test Page</h1>			</header><!-- .entry-header -->

		
		<div class="entry-content" itemprop="text">
			<h3>180</h3>



<div id="wpv-view-layout-347-CATTR535f528c00cb23405926bf9eb5d9f7a3TCPID125" class="js-wpv-view-layout js-wpv-layout-responsive js-wpv-view-layout-347-CATTR535f528c00cb23405926bf9eb5d9f7a3TCPID125" data-viewnumber="347-CATTR535f528c00cb23405926bf9eb5d9f7a3TCPID125" data-pagination="{"id":"347","base_permalink":"/test-page/?wpv_view_count=347-CATTR535f528c00cb23405926bf9eb5d9f7a3TCPID125&wpv_paged=WPV_PAGE_NUM","query":"normal","type":"disabled","effect":"fade","duration":500,"speed":5,"pause_on_hover":"disabled","stop_rollover":"false","cache_pages":"enabled","preload_images":"enabled","preload_pages":"enabled","preload_reach":1,"spinner":"builtin","spinner_image":"<em><u>hidden link</u></em>","callback_next":"","manage_history":"enabled","has_controls_in_form":"disabled","infinite_tolerance":"0","max_pages":0,"page":1,"loop":{"type":"","name":"","data":[],"id":0}}" data-permalink="/test-page/?wpv_view_count=347-CATTR535f528c00cb23405926bf9eb5d9f7a3TCPID125">

	
	
	<ul class="wpv-loop js-wpv-loop">
		
			<li>
Mike Tankle,
Cashier I on
Grave shift
<a href="<em><u>hidden link</u></em>"> (View)</a>
<a href="<em><u>hidden link</u></em>" > (Edit)</a></li>
		
	</ul>
	
	
	
</div>

<p><!- View not found ->&#8216;]</p>
		</div><!-- .entry-content -->

			</div><!-- .inside-article -->

#735114

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Mike,

I dont think the issue here is necessary the quotes. Did you add the shortcode name "sbf_return_current_supervisor" to the views 3rd party shortcode arguments ?

If not could you try doing this and let me know if it starts working.

Thanks,
Shane

#736004

Call me dummy! I used hyphens instead of underscores in the arguments. That fixed it. Thanks!

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