Skip Navigation

[Gelöst] Insert custom field slugs in a link of custom fields

This support ticket is created vor 3 Jahre, 4 Monate. 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.

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
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 11 Antworten, has 4 Stimmen.

Last updated by jean-francoisB vor 3 Jahre, 4 Monate.

Assisted by: Nigel.

Author
Artikel
#1830325
Capture d’écran, le 2020-10-30 à 23.05.22.png

Tell us what you are trying to do?

I have a list of custom field generated with this code :

<wpv-loop>
[wpv-item index=split2]

  • [types field="profession-certificatoins-metier-formations" separator="
  • "][/types]

</div><div class="col-sm-6">
[wpv-item index=other]

  • [types field="profession-certificatoins-metier-formations" separator="
  • "][/types]

</wpv-loop>

This give me the list of available items into the profession-certificatoins-metier-formations custom fields. I need to link each of them to their own page (search result) using their slug.

For example, this would be the link of one item : hidden link

Where Brain+Gym (at the end of the link) is the slug. How can I link each item to their search result page using their slug?

Is there any documentation that you are following?

Didn't find other forum thread talking about this.

Is there a similar example that we can see?

What is the link to your site?

hidden link under Liste de partenaires tab

#1831035

Jamal
Supporter

Languages: Englisch (English ) Französisch (Français )

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

Hello and thank you for contacting the Toolset support.

Toolset will not create the links out of the box, you will need to create the links within your view. For that, you can't use the types shortcode with the separator argument. You will need to wrap the typesshortcode within the wpv-for-each shortcode and build the link within it. Read more about wpv-for-each here https://toolset.com/documentation/programmer-reference/views/views-shortcodes/#vf-153482

Something like:

[wpv-for-each field="wpcf-profession-certificatoins-metier-formations"]
<a href="<em><u>hidden link</u></em> field='profession-certificatoins-metier-formations'][/types]">[types field='profession-certificatoins-metier-formations'][/types]</a>
[/wpv-for-each]

Note that we need the "wpcf-" prefix in the wpv-for-each shortcode argument.

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

#1833849
Screenshot_2020-11-03 Modifier le groupe ‹ PSM - Les Partenaires Santé et Mieux-Être Québec — WordPress.png
Capture d’écran, le 2020-11-03 à 16.08.45.png

Hi,

Actually, that doesn't work. The list that is created is a list of everything in the field for each custom post actually in the website (see attached). What I want is a full list of ALL options available from the field profession-certificatoins-metier-formations (see attached for the full list). I want this full list of ALL options with a link on each that bring me to a search results of each one.

Thank you for your help.

#1833867

Something like this could work but I would need to edit the code every single time that we add or remove an option from the list. I want the list to update automatically when we do some change to it. Is that possible?

    [wpv-conditional if="( '[types field='profession-certificatoins-metier-formations' option='0'][/types]' eq '1' )"]

  • Option 1
  • [/wpv-conditional]

    [wpv-conditional if="( '[types field='profession-certificatoins-metier-formations' option='1'][/types]' eq '1' )"]

  • Option 2
  • [/wpv-conditional]

    [wpv-conditional if="( '[types field='profession-certificatoins-metier-formations' option='2'][/types]' eq '1' )"]

  • Option 3
  • [/wpvconditional]

Thank you!

#1836371

Minesh
Supporter

Languages: Englisch (English )

Timezone: Asia/Kolkata (GMT+05:30)

Jamal is on Vacation. This is Minesh here and I'll take care of this ticket. Hope this is OK.

As I understand, you only want to display the checkbox options that is checked for the specific post - correct?

#1836611

Hi Minesh,

I didn't expected my request to be that hard to understand.

No, what I want to show is only a list of ALL the options available in the custom field profession-certificatoins-metier-formations but NOT related to any post at all, just a list of all available choices from that specific custom field.

Actually, when I create a CRED form and I add this custom field to it, I'm getting the full list with checkbox and visitor can select what they want from the list. It is exactly what I want, the same list but without the checkbox, just a RAW list of all choices.

And I would like this list to be dynamic because eventually, visitor will be able to add more options to that custom field into the CRED form that I also created in a different section of the website.

So this is the shortcode I use to show this list of option in the CRED form :

[cred_field field='profession-certificatoins-metier-formations' force_type='field' class='form-check-input' output='bootstrap']

Can I use it into View? Or is there any similar code that I can use in view to get this list published into the front-end without being in a form?

Thank you!

#1839027

Nigel
Supporter

Languages: Englisch (English ) Spanisch (Español )

Timezone: Europe/London (GMT+00:00)

Hi there, sorry to bump you around but Jamal is still on vacation and Minesh is sick, so let me step in here.

If I understand you correctly, you have a checkboxes custom field, and you want to output all of the options belonging to that custom field (regardless of whether they are assigned to any posts or not) as links in some particular format.

There are no shortcodes or blocks that can be used for this, you will need a bespoke solution.

Given that you are trying to print links on the screen you should probably register a custom shortcode.

https://developer.wordpress.org/plugins/shortcodes/

You can use the internal API function types_get_field to get the field settings for your checkboxes field and extract the options to then do what you want with (create links).

Given that your custom field has a slug "profession-certificatoins-metier-formations" then you can retrieve the field settings for that custom field with

$field_settings = types_get_field( 'profession-certificatoins-metier-formations' );

If you dump that to your error log you can inspect what it contains, but the options themselves are available like so:

$field_options = $field_settings['data']['options'];

You can then loop over these field options and you'll have the option title available as an array element with key 'title' and the option value to save available as an array element with key 'set_value', and generate a string of markup containing the links as required.

Sorry, but writing such custom code is outside the scope of support, but if you get stuck on something specific let us know and we'll try to help.

#1843643

Hi,

Thank you very much for your help. Unfortunately, I don't have the proper knowledge of coding to be able to create this function. I will definitely need help from someone to create it.

The thing that I know is that if I get this done, I will reuse this code at many different other places and different websites. And I think that could be useful for other people who try to reproduce the same function. I understand this is going outside of the scope of support... but if you think that can be done quickly, I will share the tricks to different ToolSet groups so more users could benefit of this.

Thank you!

#1846271

Nigel
Supporter

Languages: Englisch (English ) Spanisch (Español )

Timezone: Europe/London (GMT+00:00)

I'll will try and offer something more specific when I have some time tomorrow.

In the meantime, can you give more details about what the options of your checkboxes field stores? You shared a screenshot showing a list of all the options above, but can you expand one of the options so I can see an example of what is stored for the label and the value?

And can you confirm, the links, they should all be to the same page containing a View, and the values from the checkboxes options should be used to provide a value for the URL parameter used to set the filter in the View, yes?

#1847993
Capture d’écran, le 2020-11-17 à 19.46.36.png
Capture d’écran, le 2020-11-17 à 19.37.49.png

Hi Nigel,

What it is stocked is the exact same information than the name (see attached). Ideally, I would like to keep it like this if it's possible.

I would like each one to have a link that bring the visitor to the search result page for that specific option. Here are the links that I have manually created while I'm waiting to get this list populed dynamically.

<li><a href="<em><u>hidden link</u></em>">*Salons Mieux-Être</a></li>
 	<li><a href="<em><u>hidden link</u></em>">*Voyages Mieux-Être</a></li>
 	<li><a href="<em><u>hidden link</u></em>">AccessBar</a></li>
 	<li><a href="<em><u>hidden link</u></em>">Arbonne</a></li>
 	<li><a href="<em><u>hidden link</u></em>">Astrologue</a></li>

So you can see the value of each options after the " = " at the end of each link.

So if I get this list to be dynamic, that mean that everytime the custom field is modified in the back end, the list get automatically adjusted to the change.

You can see how the list is published here : hidden link
Under "Répertoire des PROFESSIONS de nos partenaires"

Thank you very much for your help!

#1851015

Nigel
Supporter

Languages: Englisch (English ) Spanisch (Español )

Timezone: Europe/London (GMT+00:00)

I put this together as a demo, which worked on my own site (with my own custom field slugs and target page).

You can add the code at Toolset > Settings > Custom Code.

You should check the slug and target values in the code to confirm that they match the requirements for your site.

add_shortcode('options', function () {

    // Edit slug and target
    $slug = 'profession-certificatoins-metier-formations';
    $target = '<em><u>hidden link</u></em>';


    $output = "<ul>";

    $field_settings = types_get_field( $slug );
    $field_options = $field_settings['data']['options'];

    foreach ($field_options as $key => $field_option) {
        
        $output .= '<li><a href="'.$target.$field_option["set_value"].'">'.$field_option["title"].'</a></li>';
    }

    $output .= "</ul>";

    return $output;
});

The code registers a custom shortcode 'options', so you can add [options] wherever you want this list of links to appear.

Note that this is custom code that really is outside the scope of normal support and is provided as-is: if you have problems using it you may need to consult a developer for help.

#1854101

Hey Nigel! You went above and beyond on this big time! I really appreciate that! And I'm sure this trick will help others trying to create something similar. This function doesn't need to be incorporated into Toolset but it would be nice. Thank you for your help!

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