Skip Navigation

[Resolved] Third-party shortcode arguments

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

Problem: I would like to use a custom function in a conditional, but I cannot get it to work as expected.

Solution: In this case it is possible to create a custom shortcode instead of a function that adds a filter and returns some result. See the below format for creating a custom shortcode that returns some value, then register the shortcode name in Toolset > Settings > Frontend Content > 3rd-party shortcode arguments.

function paid_memebers_filter() {
  $value = 'notpaid';
  // ... your code should modify $value here if necessary...
  return $value;
}
add_shortcode( 'paidviewfilter', 'paid_memebers_filter' );

Then you can use it in a conditional like so:

[wpv-conditional if="( '[paidviewfilter][/paidviewfilter]' eq 'paid' )"]
...paid content...
[/wpv-conditional]
[wpv-conditional if="( '[paidviewfilter][/paidviewfilter]' eq 'notpaid' )"]
...unpaid content...
[/wpv-conditional]

Relevant Documentation:
https://toolset.com/documentation/user-guides/views/shortcodes-within-shortcodes/

This support ticket is created 4 years, 2 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Tagged: 

This topic contains 2 replies, has 2 voices.

Last updated by curtisT-2 4 years, 2 months ago.

Assisted by: Christian Cox.

Author
Posts
#1844953

Tell us what you are trying to do?
I have created a function which I am trying to use within the if condition arguement. I followed the instruction in the document

Is there any documentation that you are following?
https://toolset.com/documentation/user-guides/views/shortcodes-within-shortcodes/
Is there a similar example that we can see?
here is my function

function paid_memebers_filter($value) {
$current_user = wp_get_current_user();
$userID = $current_user->ID;
$sid = get_the_ID();
$value[] = "";

$args = array(
'post_type' => 'seller',
'post_id' => $sid,
'post_status' => 'publish',
'posts_per_page' => 1
);
$argsb = array('post_type' => 'paidedviewer');
$loop = new WP_Query($argsb);
while($loop->have_posts()){
$loop->the_post();
$seller_id = types_render_field( "seller_id", array( 'raw' => true) );
$customer_id = types_render_field( "customer_id", array( 'raw' => true) );
if($userID == $customer_id && $sid == $seller_id && is_user_logged_in()){
$value = "paid";
}else{
$value = "notpaid";
}
return $value;
}
wp_reset_query();
}

add_filter( 'paidviewfilter', 'paid_memebers_filter' );

What is the link to your site?
hidden link

#1845079

Hello, when adding a shortcode using 3rd-party shortcode registration, normally you would create a custom shortcode that returns some value rather than creating a filter function. Here is an updated example of the PHP code that you would use to create such a shortcode:

function paid_memebers_filter() {
  $value = 'notpaid';
  // ... your code should modify $value here if necessary...
  return $value;
}
add_shortcode( 'paidviewfilter', 'paid_memebers_filter' );

After that, you can register paidviewfilter in 3rd-party shortcode arguments. Then you can use it in a conditional like so:

[wpv-conditional if="( '[paidviewfilter][/paidviewfilter]' eq 'paid' )"]
...paid content...
[/wpv-conditional]
[wpv-conditional if="( '[paidviewfilter][/paidviewfilter]' eq 'notpaid' )"]
...unpaid content...
[/wpv-conditional]

Let me know if you have additional questions about this process, and I can offer more guidance. Thank you!

#1845295

My issue is resolved now. Thank you!