Skip Navigation

[Resolved] Movie poll

This support ticket is created 5 years, 4 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.

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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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: Asia/Kolkata (GMT+05:30)

This topic contains 9 replies, has 2 voices.

Last updated by martinH-10 5 years, 4 months ago.

Assisted by: Minesh.

Author
Posts
#1281351
2019-07-02_0-22-19.png

I am trying to save data to custom fields in repeatable group to make a movie poll. I had opened ticket number: #1199537

I tried to make it working, but It does nothing. Can you tell me, what is wrong? hidden link

//movie poll
add_action('cred_save_data','upvote',10,2);
function upvote($post_id,$form_data) {
    if ($form_data['id']==737) {
		$current_user = wp_get_current_user();
		update_post_meta( $post_id, 'wpcf-voter-nicknames', $current_user, true );
	}
	else {
		$votes = get_post_meta( $post_id, 'wpcf-vote-count' );
		$increase = (1 + $votes);
		update_post_meta( $post_id, 'wpcf-vote-count', $increase, true );
	}
}
#1281489

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Can you please share the old ticket URL?

I need to understand first the structure. is vote-count field is part to repeating field group?

If you can share problem URL and access details that will help me to understand your structure.

I have set the next reply to private which means only you and I have access to it.

#1281679

Minesh
Supporter

Languages: English (English )

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

Can you please share the problem URL where you added the view?

#1281703

Yep, it is in the first post: hidden link , thanks

#1281745

Minesh
Supporter

Languages: English (English )

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

I checked on your install and I see you added the form to view:
=> hidden link

When I checked the form - the form belongs to the "events" post type:
=> hidden link

As I understand - you wanted to update the vote for the field "vote count" which belongs to the repeating field group "Movie info". I think you need the select post type "movie info" and create the edit form so that you can update the vote to the selected movie.

Please check the following Doc:
=> https://toolset.com/documentation/getting-started-with-toolset/creating-and-displaying-repeatable-field-groups/front-end-forms-for-repeatable-field-groups/#forms-for-editing-values-of-existing-repeatable-field-groups

Please correct me if I misunderstand your query.

#1281759

Thats the point! I have changed the form to edit the repeatable group, cool.

But still it does nothing when I vote. Can you help me fix the PHP function?

#1281777

Minesh
Supporter

Languages: English (English )

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

I've set the following for to "edit":
=> hidden link

Then, I've removed the code you added to the functions.php file and adjusted and added the code to the "Custom Code" section of Toolset:
=> hidden link

add_action('cred_save_data','func_upvote',10,2);
function func_upvote($post_id,$form_data) {
    if ($form_data['id']==737) {
		$votes = get_post_meta( $post_id, 'wpcf-vote-count',true);
		$increase = (1 + $votes);
		update_post_meta( $post_id,'wpcf-vote-count', $increase);
	}
}

As you can see now with the following link and click on submit button the vote is increased:
=> hidden link

Do you also want to store the field "voter-nicknames" with the current logged in user nickname each time?

More info:
=> https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/

#1281841

Wow! that is cool, i didnt know i can add the code to the toolset custom code. Cool.

I need to save the voter nickname and also disable him vor other vote on current post. Is it possible? Then it should display all voters there.

#1281843

Minesh
Supporter

Languages: English (English )

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

Glad to know that solution I shared help you to resolve your vote count issue. May I kindly ask you to open a new ticket with each question you may have. This will help other users searching on the forum as well as help us to write correct problem resolution summary for which ticket originally submitted.

#1281953

My issue is resolved now. Thank you!