Skip Navigation

[Resolved] Passing URL parameters from repeatable field group.

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

Problem:
The user would like to create a link from post custom fields and fields in a Repeatable field group using a view.

Solution:
The view is used inside a tag, its return needs to be clean from new lines and HTML tags. Check the custom code solution in this reply https://toolset.com/forums/topic/passing-url-parameters-from-repeatable-field-group/#post-2024185

This support ticket is created 3 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 – 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: Africa/Casablanca (GMT+01:00)

This topic contains 4 replies, has 2 voices.

Last updated by attilaT 3 years ago.

Assisted by: Jamal.

Author
Posts
#2023619

I have a CPT 'trainings' with custom fields: date, length, status, etc.
and a repeatable group field: exercise name, reps, sets, weight and time

I made a view where I list certain trainings. I'd like to add a link to each training in the view where I pass URL parameters like:
<a href="localhost/?edat=[types field='date' style='text' format='Y.m.d.'][/types]&estat=[types field='status'][/types]&etip=[types field='tipus']">Link</a>

It's working well so far, but I should pass a few parameters from the repeatable group field too.

For this I made a new unformatted view called 'URL helper' with this template:
&ename[tssnippet-loop-iteration]=[types field='exercise-name'][/types]&eset[tssnippet-loop-iteration]=[types field='set'][/types]&erep[tssnippet-loop-iteration]=[types field='reps'][/types]&ewe[tssnippet-loop-iteration]=[types field='weight'][/types]&eti[tssnippet-loop-iteration]=[types field='time'][/types]

I added this view to the end of the URL in the original View like this:
<a href="localhost/?edat=[types field='date' style='text' format='Y.m.d.'][/types]&estat=[types field='status'][/types]&etip=[types field='tipus'][wpv-view name="URL-helper"]">Link</a>

This way a managed to build the link with all the parameters I need but somehow it mess up my link by adding some line breaks before and <span class=" cp-load-after-post"=""> tag to the end of the link.

I suspect I should change something in the URL-helper View, but cant figure out what to do.

Thanks in advance!
Attila

#2023621

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Hello and thank you for contacting the Toolset support.

To better assist you, I would like to take a closer look at the view and the content template. Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **

Please provide as many details as possible. URLs in the backend and in the frontend where we can see this link. A test scenario, such as:
For this post xxx.
I expect the URL to be like: xxx
Instead I get xxx

#2024129

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

I believe the login form is hidden using a plugin, I am unable to reach wp-login.php or wp-admin. I get a 404 error. Can you update the login URL, and double-check the credentials? Your next reply will be private to let you share credentials safely.

#2024185

Jamal
Supporter

Languages: English (English ) French (Français )

Timezone: Africa/Casablanca (GMT+01:00)

Because you are using the view inside an attribute of the <a> tag, you need to make sure that the view is clean from line breaks, whitespaces, HTML tags, etc.

I added the following code to Toolset->Snippets->Code, to remove some views comments that are used by Toolset:

add_filter( 'wpv_filter_wpv_view_shortcode_output', 'prefix_clean_view_output', 5, 2 );
function prefix_clean_view_output( $out, $id ) {
  $ids = array( 885 );
  if ( in_array( $id, $ids )) {
    $start = strpos( $out, '<!-- wpv-loop-start -->' );
    if (
      $start !== false
      && strrpos( $out, '<!-- wpv-loop-end -->', $start ) !== false
    ) {
      $start = $start + strlen( '<!-- wpv-loop-start -->' );
      $out = substr( $out , $start );
      $end = strrpos( $out, '<!-- wpv-loop-end -->' );
      $out = substr( $out, 0, $end );
    } else {
      $start = strpos( $out, '>' );
      if ( $start !== false) {
        $out = substr( $out, $start + 1 );
        $end = strpos( $out, '<' );
        $out = trim(substr( $out, 0, $end ));
      }
    }
  }
  return $out;
}

Note the view's ID at line 3 (885).

At this stage, the return of the view still contains new line breaks and two HTML tags used by Toolset(div and script). I created the following shortcode to generate the view and clean it up from the HTML tags(<div> and <script>) and white spaces.

add_shortcode('prefix-link', function(){
  $out = render_view(array(
    'name' => 'edzesprogram-url-seged'
  ));
  $out = preg_replace('/\s\s+/', '', $out);
  $out = preg_replace( "/(<div.*?<\/div>)/is", '', $out );
  $out = preg_replace( "/(<script.*?<\/script>)/is", '', $out );
  return $out;
});

And used the shortcode instead of the view.

<a href="<em><u>hidden link</u></em> field='datum' style='text' format='Y.m.d.'][/types]&estat=[types field='edzes-statusza'][/types]&etip=[types field='edzes-tipusa'][/types]&ejel=[types field='edzes-jellege'][/types]&ehos=[types field='edzes-hossza' format='FIELD_VALUEperc'][/types]&eleir=[types field='leiras' output='raw'][/types][prefix-link]">PROBLEMATIC LINK</a>

Please note that I moved the link code from the content template to the loop's directly in hidden link

I hope this helps. Let me know if you have any questions.

#2024193

It works like a charm.
Thank you very much Jamal!

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