Skip Navigation

[Résolu] Pull out data from Toolset

This support ticket is created Il y a 6 années et 3 mois. 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.

Aucun de nos assistants n'est disponible aujourd'hui sur le forum Jeu d'outils. Veuillez créer un ticket, et nous nous le traiterons dès notre prochaine connexion. Merci de votre compréhension.

Sun Mon Tue Wed Thu Fri Sat
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

Ce sujet contient 27 réponses, a 3 voix.

Dernière mise à jour par Ljuba Il y a 6 années et 3 mois.

Assisté par: Beda.

Auteur
Publications
#1073586
001.png
002.png
003.png
004.png
005.png

==> Tell us what you are trying to do?

I'm writing, expecting Beda to take ticket.

1) Form done with Formidable Pro working like 'Swiss clock' (exactly as I wanted) and you can see it by click on 'Reservar ahora' (and images). You can see that it is very simple form and nothing special and close to some Booking Management application, some CRM, or whatever.

2) Remaining issue is that your code to pull data from Toolset, from other ticket not working. So, now it is as

add_filter('frm_setup_new_fields_vars', 'frm_populate_posts', 20, 2);
add_filter('frm_setup_edit_fields_vars', 'frm_populate_posts', 20, 2); //use this function on edit too
function frm_populate_posts($values, $field){
  if($field->id == 67){ //replace 125 with the ID of the field to populate
    $post_id == //The current Hotel Post or any Hotel Post ID
    $posts = toolset_get_related_posts(
        '$post_id', // get posts related to this one
        'alojamiento-habitacion', // relationship between the posts
        'parent', // get posts where $post_id is the parent in given relationship
        $limit, $offset, // pagination
        array(),
        'post_id' // you want the post ID, could be object to
        'child'//return child post(s)
    );
    unset($values['options']);
    $values['options'] = array(''); //remove this line if you are using a checkbox or radio button field
    foreach($posts as $p){
      $values['options'][$p->ID] = $p->post_title;
    }
    $values['use_key'] = true; //this will set the field to save the post ID instead of post title
  }
  return $values;
}

3) Error is

The code snippet you are trying to save produced a fatal error on line 13:
syntax error, unexpected ''child'' (T_CONSTANT_ENCAPSED_STRING), expecting ',' or ')'

The previous version of the snippet is unchanged, and the rest of this site should be functioning normally as before.

Please use the back button in your browser to return to the previous page and try to fix the code error. If you prefer, you can close this page and discard the changes you just made. No changes will be made to this site.

4) As it is possible also to pull out number of each room, how should to look code for that 'dynamic field'? Slug of this field is 'numero-de-habitaciones-de-este-tipo'.

#1074743

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Ljuba - Beda do not work on Monday as its his weekend. For now, I can see one issue with the code you shared and I will try to assist you and if that does not help to resolve your issue, as you already requested, I will pas the ticket tomorrow to Beda.

The issue I can see is there is missing comma with your second last argument 'post_id' with function toolset_get_releated_posts. It should be 'post_id',

Could you please try to use following code and try to resolve your issue:

add_filter('frm_setup_new_fields_vars', 'frm_populate_posts', 20, 2);
add_filter('frm_setup_edit_fields_vars', 'frm_populate_posts', 20, 2); //use this function on edit too
function frm_populate_posts($values, $field){
  if($field->id == 67){ //replace 125 with the ID of the field to populate
    $post_id == //The current Hotel Post or any Hotel Post ID
    $posts = toolset_get_related_posts(
        '$post_id', // get posts related to this one
        'alojamiento-habitacion', // relationship between the posts
        'parent', // get posts where $post_id is the parent in given relationship
        $limit, $offset, // pagination
        array(),
        'post_id',   // you want the post ID, could be object to
        'child'      //return child post(s)
    );
    unset($values['options']);
    $values['options'] = array(''); //remove this line if you are using a checkbox or radio button field
    foreach($posts as $p){
      $values['options'][$p->ID] = $p->post_title;
    }
    $values['use_key'] = true; //this will set the field to save the post ID instead of post title
  }
  return $values;
}

Could you please try to use above code and try to resolve your issue.

#1074769

Unfortunatelly, your code completely break website post (not website itself).

#1074770

Minesh
Supporter

Les langues: Anglais (English )

Fuseau horaire: Asia/Kolkata (GMT+05:30)

Well - I have done nothing but added just comma to the code your shared and shared the solution with you as that is the correct syntax:

'post_id', 

so, as you suggested, I will assign the ticket to Beda. He will be in touch with you when he will back tomorrow.

#1075049

Don't worry. I know that problem can't be done by one point (but not working).

#1076155

The error you got and Minesh solved, is accurately solved.
I had made a typo in my example.

The Field you try to populate, you showed me the example, used in that example a get_posts() to get ID's of posts.

Now, that is the only what I can help you here in relation to Toolset, and to get related posts, you use toolset_get_related_posts()

That function expects a few things, like the post id you want to get related posts from, the relation, etc.
Those are just like other PHP Function arguments.
$post_id == //The current Hotel Post or any Hotel Post ID

This is not populated, hence, what should it return?

You must populate the API call with your data, just as the get_posts() requires that as well.

In the example you showed me, get_posts() gets posts of a certain type:
alojamiento
https://toolset.com/forums/topic/repeater-fields-groups-in-cred-working/page/2/#post-1073456

Now, if you only need to get all posts of a type, just use that (get_posts)
If you need to get posts, related to a certain post, use the toolset_get_related_posts(), and pass an ID of a post to which you want to get the related posts from.

Try your code with an ID of a valid related post.

Related to wether you can get fields from those returned posts, sure, this is again a WordPress API:
get_post_meta()
This requires as well again Post ID to get data from
https://developer.wordpress.org/reference/functions/get_post_meta/
The only special here is that if you use get_post_meta() you need to prefix the post meta key with wpcf-
So numero-de-habitaciones-de-este-tipo becomes wpcf-numero-de-habitaciones-de-este-tipo
This is explained here:
https://toolset.com/documentation/customizing-sites-using-php/functions/

Does this solve the issue?
If not, can you add all required log in data and let me see the example?
==> Please enable WP Error debugging when you deal with code, and add the code to functions.php, instead of thru the Admin, it is easier to know where issues are.

#1077182

1. Great

I think (maybe) you could be interested in a Custom Theme, I think you will have a lot to customize in future.
I created a Toolset Ready Theme boilerplate a while ago, thought to share it with you:
lien caché
==> This is not a Toolset product, no support for this Theme is provided here
==> However it is a greatly documented Theme boilerplate to make custom themes that are based on Toolset - and keep it as minimal as even possible.

Maybe you can use it, who knows.
Remember, this is just something I created, not a Toolset product, I share with you for your own usage if you want.

I sometimes feel, complex sites are not best kept with complex themes that come with lots of predefined settings and options, but should be as minimal as possible. That depends a lot on your needs.

2. I tried our code, revised, and I see there must be a PHP error and as I instructed, when developing code, we need WP Debug active, always.
Please enable it.

Then we can see the error and fix it.

I can't as you did not provide the FTP details, otherwise I would done this.

3. It's not yet needed to bother Formidable Forms DEV.

4. I totally understand what you do there, and you can do the same in Toolset.

There are 2 ways to do that:
- post reference field (as seen in Toolset > Custom Fields > Post Fields > Add New). This can also be used in Toolset Forms later.
- Custom code applied to a Toolset Select Field, with our filter "wpt_field_options"

The filter wpt_field_options can be used to manipulate the options of select and radio field.

Arguments

$current_options
$title (the title of the field)

Output: Array

Required format:

array(
    array(
        '#title' => 'First Title',
        '#value' => 'first-value'
    ),
    array(
        '#title' => 'Second Title',
        '#value' => 'second-value'
    ),
)

Example of usage:
Let's assume your theme has a colorset of dark, light and accent color, which are editable in the theme options. The theme stores these values as a wp_option theme_name_colorset in this format:

array(
    'Dark'         => '#333333',
    'Light'        => '#eeeeee',
    'Accent Color' => '#ff3300'
)

Now we adding this function to our themes functions.php:

add_filter( 'wpt_field_options', function ( $current_options, $title_of_field ) {
    if ( $title_of_field != 'Headline Color' ) {
        // not our "Headline Color" field
        return $current_options;
    }

    $theme_colorset = get_option( 'theme_name_colorset' );

    if ( ! $theme_colorset ) {
        // no theme colors are set yet
        return array(
            array(
                '#title' => 'No colors available',
                '#value' => 0
            )
        );
    }

    $new_options = array();
    foreach ( $theme_colorset as $color_title => $color_value ) {
        $new_options[] = array(
            '#title' => $color_title . ' (' . $color_value . ')',
            '#value' => $color_value
        );
    }

    return $new_options;
}, 10, 2 );

Now your Toolset Types select field would show (in the post where you edit it) the above set custom values.

Note:
¡¡¡ Fields, populated with wpt_field_options() will NOT work in Toolset Views Custom Searches (as not automatically populated there) !!!

I see thou the ease that Formidable provides to customize the field options, it's nice.

We should have something similar in Forms.

We do, for example Generic Fields.
They can persist, in the database, if you pass "persist:1" in the Generic Field that the form inserts.
That generic Field can even be populated with a View (using some custom filters).

Please can you A) Enable debug on the site so we can solve the issue of this Ticket, and B) if you are interested in the other approaches and need help, please contact me thru a new ticket each issue/question.

Thank you!

#1077202

1) First to write that debug is enabled and here is log (but you can keep on as I will let it enabled).

Notice: Undefined variable: limit in .../wp-content/plugins/code-snippets/php/snippet-ops.php(352) : eval()'d code on line 10

Notice: Undefined variable: offset in .../wp-content/plugins/code-snippets/php/snippet-ops.php(352) : eval()'d code on line 10

Fatal error: Uncaught InvalidArgumentException: The provided argument for a related element must be either an ID or a WP_Post object. in .../wp-content/plugins/types/vendor/toolset/toolset-common/inc/public_api/m2m.php:77 Stack trace: #0 .../wp-content/plugins/code-snippets/php/snippet-ops.php(352) : eval()'d code(13): toolset_get_related_posts('$post_id', 'alojamiento-hab...', 'parent', NULL, NULL, Array, 'post_id', 'child') #1 .../wp-includes/class-wp-hook.php(288): frm_populate_posts(Array, Object(stdClass)) #2 .../wp-includes/plugin.php(203): WP_Hook->apply_filters(Array, Array) #3 .../wp-content/plugins/formidable/classes/helpers/FrmFieldsHelper.php(96): apply_filters('frm_setup_edit_...', Array, Object(stdClass), 0, Array) #4 .../wp-content/plugins/formidable/classes/helpers/FrmFieldsHelper.php(79): FrmFieldsHelper: in .../wp-content/plugins/types/vendor/toolset/toolset-common/inc/public_api/m2m.php on line 77

2) I can't enable to nobody FTP (to not explain now why, maybe is enough to say that server is on Google)

3) I will see now the rest of the post if something is for reply and than go to sleep.

#1077257

1) CUSTOMIZATION'S

a) I actually don't think that I will make some real customization's (or to 'invent' something new). Goal of the project is quite simple = Make it > Make it to work > Make it to get it sold (idea/project). To sell something, I must to have to show something. Simple.

b) I'm using CobalApps Genesis customizer pack and in couple of hours I can get easy whatever I need from project. However, I don't like to do this part of the job (but ... what must be done ...).

c) For 'normal' jobs (customers), I'm prefer to use Divi (as I don't like neither to think, not just to work - BTW, that's why I'm in tropical Ecuador).

d) Somehow (did you 'smell it' or saw it?), the fact is that I opened another ticket couple hours ago (Optimizations > Nigel chosen) with questions vs final advice's. Briefly, with THIS TOPIC, I think that I mainly have project closed (now is to rewrite it from scratch) as this line = Destinos > Negocios > Alojamientos > Habitaciones > Camas = is most complicated 'branch'. ENTIRE WEBSITE WILL LOOK THE SAME (single.php), as it simply must to be the same. Of course, I will still have the issues and some support questions, but anymore some really 'problematic' (one, I know already now).

e) Briefly, Genesis child will be as it looks now. Elementor will be dropped out (no page builders, just Bootstrap). I simply want to reduce all (you saw, it is irrational) to fit in 'right measures'. Controversially, to successfully make it something good, first must to be big and than, finally reduced. When first single.php will be redesigned (content, structure and look/feel), remains archives (and harder part of the task (irrelevant here). It should not to 'jump out' so different than any other known website of such kind.

f) So, there is no possible way that I will in this stage, start to search, look and/or learn something new. I downloaded your theme and yes, I'm curious to see what you packed in only 218.9 kb (my child is 105 kb plus Genesis, so you get impressive number). However, that cannot be for this occasion (project), as I simply, can't start over.

2) "I totally understand what you do there, and you can do the same in Toolset."

but you also wrote

"¡¡¡ Fields, populated with wpt_field_options() will NOT work in Toolset Views Custom Searches (as not automatically populated there) !!!"

I simply don't need it. ANY BOOKING WILL BE STORED on server, as that is too far from project goal. This Formidable form, doing 101% EXACT what I need, no more and no less. Compact, efficient and nice looking (also, easy to fit anywhere).

However, I'm not so sure how Toolset can to create so efficient work-flow (repeaters included), but irrelevant now.

3) FORMIDABLE vs TOOLSET

3A) EFFICIENCY

==> I think that you didn't noticed HUGE DIFFERENCE in conditional logic. Formidable ask ONLY LAST FIELD IN THE CHAIN, Toolset ask ENTIRE CHAIN (do you remember other ticket?).

3B) EFFICIENCY & FOOTPRINT (performances)

==> Current Formidable & Formidable PRO are together 2.2 + MB (and all addons are cca 3 MB, if you need it at all).

==> Current CRED (Toolset Forms) & Views are together cca 16 + MB (so, 7+ times more of the PURE CODES ???).

==> MOST INTERESTING I'm pretty much positive that Formidable with addons have absolutely non comparable advantage in numbers and variations of usage. Yes, they have forms and VIEWS (also), as standard part of the plugin.

3C) STYLING I'm actually surprised that Toolset persistently handle only 'old companions' (Bootstrap 3 FA 4, JQUERY ???). I want to say, Toolset by itself 'pull back' its own progress and development as it is grounded on 'full codes' approach (ie - what about jQuery UI, Bootstrap 4, ...?). Formidable instead use it as they are - third party tools. That's why Formidable form is without hasle much more nice than Toolset Form. Try just to compare data picker or drop down or sliders (sorry, Toolset missing support for it - sorry, joke). Formidable let's third party tools to do its own jobs (ie just see integration via Zapier) and Toolset want to do EVERYTHING. That's wrong.

Observe just practical and not so naive example (my other, never solved ticket by Luo).

WYSIWYG HTML Editor

Instead that Toolset development and support will be focused on its own features, you spend huge resources for persistently repeated issues related to editor. How to limit characters, disable right click, disable image insertions, how to .... and so on. ALL OF THAT IS SOLVED LONG TIME AGO by TinyMCE itself (well done docs and bunch of examples). Problem is that Toolset is NOT CAPABLE TO APPLY TinyMCE java code for customizing all this behaviors (and per editor instance is possible, not just site wide). That make you sense?

FINALLY

Don't take me wrong, this are not critics. It is about observations as if Toolset by itself not notice how 'spiral circle of codes' will most likely 'kill Toolset' (question is when it will be). Toolset should to think about integration's (CRM, HIPAA compliance's, bookings, payments, ...), as there are the clients (money), but for me it not looks like scenario for future. It looks that Toolset like to develop itself for itself (and some small trial sites), instead to run to be in line with other competitors.

Just try to observe what you can do with Formidable Pro + Pods (4 minus MB footprint) and try to list Toolset capabilities. Maybe, that will 'push' Toolset to start to think. BTW, just arrived answer by Nigel about my ticket on Bootsrap 3 & 4.

I think that I'm (kind of) at the end of the project and I'm overall satisfied with Toolset and support (especially, couple of the supporters).

#1078354

Hey Ljuba

1. The code error can be fixed by defining those variables.
I must have been sleeping when I wondered what breaks the code.
I fixed the issue by passing 99, 0 to the variables.
The Select field is now populated, but somehow it does not trigger the field when clicked (I can see the values populated but as well a JS error).
That may be another conflict, I am not sure what causes it
Seems Formdable is throwing this, but I am not sure why, the values are the same as if the get_posts is used, now, and the issue even happens if you use your initial snippet.

It may be another cause, the code is working now

2. Related to your feedback I generally agree, some of the features you speak of are making it to Toolset in Future, others, are not yet in the Roadmaps, and always we will try to make it better as well using such feedback.

I actually think, unluckily, the sentence "It looks that Toolset like to develop itself for itself (and some small trial sites), instead to run to be in line with other competitors." is true, by fact. This is how it started. We needed a Tool to make it easier to create Website (our, of course) and created Toolset.
We saw how good it is and developed it.

But of course, you are right that the initial "flair" is probably still deep in Toolset, and it needs to become more then the initial idea (Well, it is already - we both agree on that - but it needs to develop more)

I will pass all this feedback to the teams as this is valuable for us.

Thanks

#1078377

1) Give me a hour and I will fix it. It is vs. cause I'm playing with Bootstrap 4 and it cause the conflict in Formidable (not Toolset). In hour. Than we cn check the Form (Formidable) and Toolset > 'together'.

2) It wasn't actually feedback. I just exposed what I noticed (and I also could be wrong). So, I personally only think similar what you exposed - Toolset is went 'out of its own pants' (grown) and maybe is time to start it from scratch (parallel) for purpose for real startups market. This Toolset can go yet (probably) a long time more for its initial purpose. However, there is the issue that Toolset should to realized what should to develop and what not, as it looks too heavy for its outcomes.

I just can repeat > I'm satisfied with Toolset as I'm near to finish what I wanted (and rest is the market).

#1078411

Thanks!

Let me know if it works after your adjustments.

#1078433

Well, I made a mess (not Bootstrap and Formidable, or you). Now I created restore from yesterday and you should to do again what you did (please be precise here, what you did and how code should to look now exactly).

I will remove ALL SNIPPETS EXCEPT ORIGINAL (that you can first see how old original Formidable code for all posts display working). Than YOU CAN REMOVE IT.

I created 3 rooms. Two are related to parent demo post and one (obvious post) is not related to ANY POST. Now in original snippet will be listed ALL 3 ROOMS.

BTW, as I replaced Elementor with Content Templates, strange thinks are started. Existing post can't 'catch' the now default template itself. Should be set manually (so, what if there is hundreds of posts???). New post 'catch' the template.

#1078434

The snippet was already edited to work fine, as stated, however, I cannot login anymore, it is showing me an error due to wrong login details

Please can you update or restore the details here:
https://toolset.com/forums/topic/pull-out-data-from-toolset/#post-1076745

#1078435

I forgot to enable your account. I'm not sure that it will work, as for me result broken (I should again to enable debug - I will now).