Skip Navigation

[Resolved] Populate field from taxonomy

This support ticket is created 6 years, 3 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)

Author
Posts
#1081468
02.png
01.png

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

I want to populate select field from taxonomy, but it not working. On images are what I should to connect and here is function.

add_filter( 'wpt_field_options', 'tarjeta_select', 10, 3);
function tarjeta_select( $options, $title, $type ) {
    if ($title == 'Tarjetas de credito aceptadas')  {
        $options = array();
        $args = array('hide_empty' => 'false');
        $terms = get_terms( array('tipo-de-tarjeta'), $args );
          
        foreach ($terms as $term) {
        $options[] = array(
        '#value' => $term->term_id,
        '#title' => $term->name
        );
    }
    }
}

What I'm doing wrong?

#1081501

Hi, the wpt-field-options function has been deprecated and could stop working unexpectedly. At this time, the best way to manage custom field values is to manually set them in the custom field editor screen. However, if you want to accept the risk and continue using this deprecated function, it must return the $options array after you manipulate the values.

#1081509

Hi,

I tried also with return and no results. So, just please let me know did I understand well (my English) when you wrote "the best way to manage custom field values is to manually set them in the custom field editor screen", you mean that I must to manually populate field values (instead from taxonomy), right?

And as function is deprecated, please let me try to figure what options I have with direct usage of taxonomies via CRED.

I created CPT child 'Payments' with 'repeater' functionality in mind. Basically, client will be by conditional logic forced always within one 'loop' to use only one set of fields combinations. So, if my list of the Banks will be taxonomy and client select several banks (in several posts), but all of them belongs to parent CPT (ie - Business), that will be fine, right?

Goal of scenario is to present clients available banks account data (on his post page), as well to be capable to enable for website visitors to filtering the businesses who accept (ie) CitiBanks transfers.

#1081607

you mean that I must to manually populate field values (instead from taxonomy), right?
Yes, that is correct.

I created CPT child 'Payments' with 'repeater' functionality in mind. Basically, client will be by conditional logic forced always within one 'loop' to use only one set of fields combinations.
Sorry I'm confused about this. Is "CitiBank transfer" an example of a Payment post, or is "CitiBank transfer" a custom field or taxonomy on a Payment post? What other information is stored in a Payment post?

Goal of scenario is to present clients available banks account data (on his post page), as well to be capable to enable for website visitors to filtering the businesses who accept (ie) CitiBanks transfers.
It is difficult to filter a View of post type A by a custom field or taxonomy on post type B. It's best if the custom field or taxonomy is applied to post type A. So can you explain in more detail why the taxonomy cannot be applied directly to the Business instead of the Payment post?

#1081644

1) Payments CPT contain 'payments media' acceptable by (ie) Business. There are in-store CC charge, online CC charge, bank transfer, cheques and other payment media (Western Union, Bitcoin, ...). Most contain common fields (set of fields for additional charges related to payment media, Banks (37 in Ecuador), beneficiary name, ..... (totally > 24 fields).

So, only possible approach is 'repeating entrances. It can be done by child SPT or RFG. I already spent over 2 months on experiments with RFG and its simply have still a lot of problems (Beda and Nigel knows for some). I remain to choose only child CPT > Payments.

2) There is additional issue, as you should to consider 'real life' situations. I have just here in small touristic town example with restaurant chain (6 locations) and some of them accept CC in-store and some not, some accept online and some not, all have common bank account for bank transfers, .... Briefly, variety of scenario's.

3) To get total 'mess', you should count that Business have 4 child CPT (Hotels, Gastronomy, Shopping and Services). So, another example is Hotel with Restaurant and SPA (3 child CPT within parent CPT of Business/Company).

ALL OF THEM have variety of charging media types what they accept.

CONCLUSION

Despite the possible issues, RFG is obviously also out of consideration. ONLY REMAIN CHILD CPT option (with relationships).

#1081735

Okay thank you for the additional information. You need a View of Businesses that can be filtered by the payment media accepted by its children in various child post types. This is tricky, because you cannot filter a View of Businesses by a custom field or taxonomy in a related child post. There are two ways to do this.

Option 1: Write custom code that copies all the selected taxonomy terms or custom field values from all the child posts and adds them to the parent Business post. Do this whenever a child post is created, edited, or deleted using the save_post or cred_save_data hooks. Filter the View of Businesses by the fields or terms on the Business post. This approach requires more custom code.

Option 2: Create two nested Views. The first View produces a list of Business IDs. The second View takes the first View as a shortcode attribute for a post ID filter. This approach takes less custom code.
- Create a View of all the child post types, filtered by the custom fields or taxonomy terms. In the Loop editor, output the parent Business post IDs as a comma-separated list like 1,2,3,4. You can use the wpv-post-id shortcode to do this.
- Apply the raw output filter to strip all the unnecessary markup from the results of this View. Remove all extra spaces from the Loop editor.
- Create a View of Businesses, filtered by post ID, where the post ID is set by a shortcode attribute "ids". In the Loop editor, output the Business title or link.
- Insert the child posts View shortcode in the post ID filter shortcode attribute of the Business View.

[wpv-view name="view-of-business-filtered-by-post-id" ids="[wpv-view name='view-of-child-post-types']"]

Here is the raw output filter if you do not have it already:

add_filter( 'wpv_filter_wpv_view_shortcode_output', 'prefix_clean_view_output', 5, 2 );

function prefix_clean_view_output( $out, $id ) {
  $ids = array( 12345 );
  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;
}

Change 12345 to match the numeric ID of the View of child posts. If you want to apply the raw filter to more than one View, add a comma-separated list of View IDs.

I'll be glad to help you set up either approach. Let me know how you would like to proceed.

#1082718

Thanks, this part is now more clear, as you confirmed that there is the way to use taxonomy in filtration (archive pages). However, we miss initial part of issue.

Is it OK to use taxonomies via CRED? (in this my situation)

EXPLANATION

Payment CPT contain 24 fields and I need taxonomies (to populate or to use directly via CRED) on 5 fields.

Initial subject of filtration should be choice of payment media ("Seleccione la medio de pago") with 6 values (here start the conditional chain). Question is > should it be field or taxonomy?

Second tricky part is fact that from 6 values, I have situation that Banks List of 37 banks appear in 3 cases (of 6) - 'in-shop payment', 'bank transaction' and 'international transfers'. Question is (again) > should it be field or taxonomy (bank list)?

REMARKS

From my experience in this time of Toolset usage, probably will be only right solution to abandon so ambitious goals, specifically as entire project is already complex. For me looks that I should to quit from idea of filtration per payments media (read > taxonomy usage) and to stick to ONLY SIMPLE 'DISPLAY' (only simple fields). It also mean, 3 different ordinary select fields for 'Bank Lists'. Right?

#1083134

Initial subject of filtration should be choice of payment media ("Seleccione la medio de pago") with 6 values (here start the conditional chain). Question is > should it be field or taxonomy?
This is a decision that only you can answer based on your knowledge of the project. Let me give you some information that can help you make the decision.
- Both custom fields and taxonomy terms can be used in Forms Conditional Groups. Both can be used to show and hide Forms inputs based on other Form input selections. https://toolset.com/documentation/user-guides/cred-conditional-display-engine/
- Both custom fields and taxonomies can be used in custom search filters, so your Users will be able to filter a View based on either type of criteria equally well.
- Both custom fields and taxonomies can be used with the "Only show available inputs" option of a View. This can help you show and hide custom search filter options based on the available results.
- Taxonomy terms can have archives automatically generated by WordPress. Custom field values cannot. If it's important to have archives of different payment types, then a taxonomy may be more appropriate.
- It can be more difficult to control the number of taxonomy terms you can apply to a post. Controlling the number of custom field values you can select can be simpler.

For me looks that I should to quit from idea of filtration per payments media (read > taxonomy usage) and to stick to ONLY SIMPLE 'DISPLAY' (only simple fields). It also mean, 3 different ordinary select fields for 'Bank Lists'. Right?
I can't answer this because I don't know everything you want to do. In more complex setups, it's difficult to ask all the right questions. Can we work from a sample site to make sure I understand what you want to accomplish, and see how things work together? Then I can make recommendations about how to change things as needed.

I have started a test site here:
hidden link

Add this to your hosts file:

74.50.54.120	biz.mi.christianc.host

I will add you as a User and send an invitation for you to log in.

#1083136

Thanks for first part (very clear explanation).

For second > I think that we can found here problem. My native language is not English (not even Spanish), but project is on the Spanish, what probably will create the problem for you to get clear picture of project. However, as it is about not so big child CPT, I can help you to understand structure after you will see.

However, I strongly recommend you to open private post and I will send you credentials for real life website and you will see also main posts and everything else. As far as I know, project should be considered like more than very complex and extraction of one child CPT probably will not help too much.

If that will not work, we can switch to test site.

#1083157

Private reply fields are enabled here. I will take a look in wp-admin and try to understand your setup.

#1083771

What you want to build is technically complex and we do not speak the same language. With that in mind, it will be best if you ask specific questions in terms of Toolset. Here are examples of questions I can answer:

- Can I use Forms Conditional Groups to display a taxonomy select field?
Yes, you can use conditional groups in a Form to display taxonomy fields. Those conditional groups can be triggered by other taxonomy field inputs, or by custom field inputs. Complex nested or chained conditions may or may not be possible depending on the conditional criteria. You should set up a test Form to see how conditional groups work with your data structures, then ask specific technical questions about any problems you encounter.

- Can I limit the number of selections in a taxonomy select field in a Form?
Yes, you can use the single_select attribute on a select field shortcode to limit the user to select only one term. You can also use the Forms API to perform more complex PHP back-end validation of Forms submissions.

- How can I implement complex front-end validation in a Form?
There is no JavaScript API for Forms, so front-end validation is outside the scope of support we provide here in the forums. I can help you implement back-end validation using the Forms API instead.

- How can I trigger JavaScript when a Conditional Group is shown or hidden?
There is no JavaScript API for Forms or Conditional Groups, so this type of functionality is outside the scope of support we provide here in the forums.

- Can I use the same taxonomy select field in multiple Forms Conditional Groups?
Yes, you can place a taxonomy select field shortcode in a Form multiple times, and use Conditional Groups to show and hide the different fields in different areas of the Form.

Here are examples of questions I cannot answer:

- Is it better to use a custom field or a taxonomy?
This is a decision only you can make based on how Forms work, how you want to display archives, how searches work, and how you want to manage data in wp-admin. I can only provide you with specific answers to specific questions, to help you make informed decisions.

- Should I use 3 different bank taxonomies?
This question is not specific enough. I will answer any specific technical question you have that will help you make this decision yourself. Refer to the questions above for examples of specific questions. Notice that I have not used project-specific keywords like "Payment" or "Gateway" or "Bank" or "Business". I am using Toolset and WordPress terminology. This helps prevent misunderstanding because of translation or lack of knowledge of your app.

#1083881

Well, I thought that finally I was clear and 'cut' entire topic to only one single question, about the different purpose of usage of the same taxonomy within CPT. We certainly cannot talk about 'generic' terms/usage/treatment/.... as everybody do it different (within WordPress). In other words, for me is complete unknown how Toolset handle taxonomies behaviors within DB, within forms, within Views. I have proof how many thinks other tool providers solved completely different than Toolset (ie Forms - shown to Beda in other topic). Example for forms, Toolset require entire chain of fields for conditional logic, Formidable Caldera,... NOT (only last field in the chain).

Back to topic and to repeat:

A) RELEVANT FACTS (for answer)

  • CPT (Payment) to where belongs taxonomy in issue (Banks) is child post (of several others).
  • As child CPT, for each post, taxonomy will appear ONLY ONCE (per single post), but possibly for different purpose.
  • Taxonomy in issue have 3 different possible usage (purpose) > CC/DC issuer - Deposits - Transfers, but they cannot act together in same single post.

B) YOUR EXAMPLES NOTE

  • You states how taxonomy can be used multiple times within post, what is obvious regards feature that taxonomy can be selected multiple times within post (but for same purpose - and my question is EXACTLY SAME, but opposite).

C) QUESTION

  • Can I use ONCE PER SINGLE POST (no more than once selected item, as well, so, select field), but FOR DIFFERENT PURPOSES?

PRACTICAL EXAMPLE (for explanation)

  • In one single post, CitiBank (one item from 27 items in Banks List taxonomy) will be used as CC/DC issuer.
  • In other single post, same item from same taxonomy (CitiBank) will be used as Bank receiver for Deposits.
  • In third single post, same item from same taxonomy (CitiBank) will be used as Bank receiver for Wire Transfers.

IMPORTANCE

It is obvious how I'm interested to have Archive Page for AVAILABLE BANKS and to filter search per AVAILABLE PAYMENTS MEDIA (CC/DC issuer - Deposits - Transfers). In real world it mean that visitor will search for hotels who accept CC/DC of certain type (VISA...) or per certain Bank Issuer (CitiBank....) or Payment Getaways (PayPal....), as they not even want to look hotels without such feature, as they are not able to make payments (makes sense, right?).

MY NOTES

  • So, for me looks obvious how that could be possible ONLY if for each Payment Media Types I will use SAME TAXONOMY, but in some other support ticket, on of supporters wrote how taxonomy per post type (WARNING -> not per post ID!!!) can be used only for ONE SINGLE PURPOSE DISPLAY (so, here is from begin about the View > final display).
  • CC/DC issuer - Deposits - Transfers, are different purpose of taxonomy usage/display, right?
#1084049

You states how taxonomy can be used multiple times within post, what is obvious regards feature that taxonomy can be selected multiple times within post (but for same purpose - and my question is EXACTLY SAME, but opposite).
A taxonomy term cannot be selected more than once in a single post for different "purposes". A taxonomy term can only be selected once in a single post.

#1084071

Dear Christian,

I'm deeply sorry as it looks how ticket went in complete wrong direction. I certainly don't want to argue, but just for the reference, you wrote:

"Yes, you can place a taxonomy select field shortcode in a Form multiple times"

and I AGREE WITH THAT (what is the essence of my statement what you quoted:

"taxonomy can be used multiple times within post"

So, your statement and my statement have words "taxonomy" and "usage", but in your last reply you write about "taxonomy term" (taxonomy item) and about "selected" (not used).

However, with this your last statement I must to disagree, as precisely, if in we in form will use MULTIPLE TIMES taxonomy selection fields and taxonomy term will be selected more than once within same single post, it can be done, BUT WILL NOT HAVE EFFECT (as it is already selected).

Problem is that I can't see what it count with my UNIQUE (and simple) QUESTION

== > Can I "use" (not select) same "taxonomy" (not taxonomy term) for different purposes?

So, Bank List is taxonomy and 27 banks are "taxonomy terms" (CitiBank is one of the 27 terms). Taxonomy term (CitiBank will be SELECTED ONLY ONCE within SAME SINGLE POST (ie for purpose as bank for deposit), but can it be selected IN OTHER SINGLE POST for different purpose (ie - as CC/DC bank issuer).

It is about very simple question.

Should I have 3 different taxonomies (with same 27 terms > banks) under different taxonomy name, or I can use ONLY ONE TAXONOMY (as terms WILL NOT BE USED OR SELECTED MORE THAN ONCE PER SINGLE POST)?

#1084074

And to be more clear, question is not from the point of view of Types or CRED, rather Views, as goal of entire topic is Archive Page (filtration).

So, there is queries about media types (CC,deposit, ....) and by selecting (ie) AVAILABLE DEPOSITS (filter one), it should to appear taxonomy (list > filter two)) of (taxonomy) terms of the banks. By selecting (taxonomy) term (ie) CityBank, should to appear businesses list (archive page) of banks who accept deposits trough CitiBank.

But, I need also other View, where by selecting the (taxonomy) term (ie CitiBank) will appear WHAT PAYMENT MEDIA TYPES ARE SUPPORTED BY BANK and with WHAT CLIENTS (businesses).

If I have 3 different taxonomies for those 27 banks, I can't see how such View will be possible. From my understandings, I MUST TO HAVE ONLY ONE TAXONOMY (list of banks) for different payments media types (also taxonomies).