Skip Navigation

[Résolu] CRED Forms – Parent Selector Fields – 2

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.

This topic contains 16 réponses, has 2 voix.

Last updated by jamesH-3 Il y a 7 années et 4 mois.

Assigned support staff: Adriano.

Auteur
Publications
#231025

Hi
This is to follow on from my first topic: https://toolset.com/forums/topic/cred-forms-parent-selector-fields/
I am still having this issue. I have just moved my site from my localhost and I am now in a position to provide you with my credentials.
I would appreciate it if you can enable the private area so I can give you that information.
I have inserted the Create New Coupon CRED form in the Coupon Manager post.
Thanks

#231032

Dear James,

Good, it is enabled right now.

#231033

Thanks mate

#231045

Dear James,

I've just followed Ana's tutorial, everything is properly set up right now, please check. The view responsible to filter parents is called "All Merchants", you can see the result in: hidden link

Now you can filter the View as you want, then the parent field will be changed.

#231077

Hi Adriano

Thanks for the quick reply; however, there are still some issues 🙁

When I login as administrator, there should be two Merchants, created by Admin (Test Merchant and James Hille Hotel); however, it is showing only one of them (Test Merchant).

When a logged in as a user (username is dreamings and you can check if if you like with the same password that I have already provided), it shows only Test Merchant but nothing else?

Thanks

#231324

Dear James,

It will be need some custom PHP code to achieve that. I've just wanted to know with it that you can use Views to populate a CRED parent field.

I will create the same environment on my localhost and to do some tests, it will take a bit of time. I will let you know as soon as I have a solution on this.

#231361

Hi Adriano
I look forward to your response
thanks

#231567

Dear James,

Before proceed implementing my solution in your site let me know the following:

1) When you are logged as Admin user, it should show only Merchants created by the Admin account, right?
2) If you are logged as any other account, it should show all Merchants of the site.

#231742

Hi Adriano

1) Yes. When I log in as admin it should preferably show only the merchants, created or assigned by to the admin user name.

2) No. When you are logged in as any other account (for example "dreamings"), it should only show the merchant(s), created by or assigned to this particular username (What I am trying to do is to allow only the merchants to post coupons for their own business(es) only)

Thanks for your help

#231975

Dear James,

Ok then, thanks. I'm going to implement this.

#232019

Dear James,

Try adding the code below in functions.php of you current theme:

add_filter( 'wpv_filter_query', 'views_filter_parents' );
 
function views_filter_parents( $query_args ) {
    global $current_user;
    
    $query_args['author'] = $current_user->ID;
    return $query_args;
}

Please let me know if you are satisfied with my answer and if I can help you with any other related question.

#232190

Hi Adriano

I have added the code to functions.php and now it does not show any of the merchants. The drop-down box is empty.

I don't know if it is a coincidence but as soon as I added this code, my little map short code (I used it in my single merchant and coupon templates) stopped working:

[res_map address="[types field="business-address-line" id="$merchant"][/types]<br/>[types field="business-city" id="$merchant"][/types],[types field="business-postcode" format="FIELD_VALUE" id="$merchant"][/types], Turkey" description="[types field="business-address-line" id="$merchant"][/types] {br}[types field="business-city" id="$merchant"][/types] [types field="business-postcode" format="FIELD_VALUE" id="$merchant"][/types] [types field="business-logo" width="60" height="60" align="center" resize="proportional" id="$merchant"][/types]" directionstext="" icon="red" style="28" pancontrol="yes" scalecontrol="yes" typecontrol="no" streetcontrol="no" zoom="15" zoomcontrol="yes" draggable="yes" scrollwheel="no" width="100%" height="300px" maptype="roadmap" popup="yes" center="" refresh="yes"]

Adriano, I do appreciate that you are doing your very best to help me on this but I would really appreciate it if you can come up with a quick solution. 🙁

Thanks

#232282

Dear James,

Sorry, my mistake. The code is fixed right now. The correct JS code should be:

jQuery(document).ready(function($) {
try {
var select = $('select[name="_wpcf_belongs_merchant_id"]');
var list = $('#aux_musicians_list') || $('div id="aux_musicians_list"></div>');
if (select.length) {
var selected = select.val();
var new_select = select.clone(true, true);
new_select.children().remove();
$('.aux_id', list).each(function(index, element) {
var id = $(element).text() || 0;
$('option[value="' + id + '"]', select).appendTo(new_select);
});
new_select.val(selected);
select.replaceWith(new_select);
}
} catch(e) {
}
});

Now, the select should shows only coupons of the logged user.

Please let me know if you are satisfied with my answer and if I can help you with any other related question.

#232404

Hi Adriano
Thanks mate and it seems to be working now.
I have got another question though. Somehow, my map shortcode, although I have not changed anything with that code, stopped working. It does not show the map anymore.
Can you see why this may have happened (is it related to your function that I have added to the functions.php)?
Also, when you were looking at the issue, it seems you have added a map shortcode to the sample-page:
[spb_gmaps address="London" size="450" type="roadmap" zoom="14" saturation="color" pin_image="26" fullscreen="yes" width="1/1" el_position="first last"]
Is it a part of Toolset? Can you direct me in the right direction to find out about how to use it, its attributes etc?
Thanks for all your help

#232413

Hi Adriano

I have sorted the map issue out.

It's all good now.

Thanks heaps