Skip Navigation

[Resolved] I have one question for the other system

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
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

This topic contains 10 replies, has 2 voices.

Last updated by lesleeM 1 year, 11 months ago.

Assisted by: Luo Yang.

Author
Posts
#2505939

I have one question for the other system that can be more easily asked here.

For this system, I wanted the registration title to be: Ride Name Registration - Registrant Name - Date

You used this code for that.

add_action('cred_save_data', function($post_id, $form_data) {

if ($form_data['id']==2083) { // speccific post form ID

$name = get_post_meta($post_id, 'wpcf-name', true);
$email = get_post_meta($post_id, 'wpcf-email', true);
$date = get_the_date('m/d/Y', $post_id);
$parent_ride_id = toolset_get_related_post($post_id, 'ride-registration', 'parent');
$parent_ride_title = get_the_title($parent_ride_id);
$post_title = sprintf('[%1$s] Registration - [%2$s] [%3$s]', $parent_ride_title, $name, $date);
$slug = sanitize_title($post_title);
wp_update_post(array(
'ID'=>$post_id,
'post_title'=>$post_title,
'post_name' => $slug
));
}
},10, 3);

For the new system using this same approach, we want the Vote title to only be:

Freelancer Name - Voting Board Member Name

with no date added. We don't have an e-mail address field on the voting form, so I deleted that from your code.

I've gotten this partially there with the following code:

add_action('cred_save_data', function($post_id, $form_data) {

if ($form_data['id']==7956) { // speccific post form ID

$name = get_post_meta($post_id, 'wpcf-name', true);
$parent_freelancer_id = toolset_get_related_post($post_id, 'freelancer', 'parent');
$parent_freelancer_title = get_the_title($parent_freelancer_id);
$post_title = sprintf('[%1$s] Board Vote - ', $parent_freelancer_title, $name);
$slug = sanitize_title($post_title);
wp_update_post(array(
'ID'=>$post_id,
'post_title'=>$post_title,
'post_name' => $slug
));
}
},10, 3);

But I'm not sure how to code this to pull the Voting Board Member Name . This data should pull the username of the author of the Vote post form submission which should be placed immediately after the bit that says Board Vote - . I'm not skilled at PHP and can only do minor edits like I've tried to do here with some success. Other than this, I believe I have this step on our next system completed. I'll post subsequent questions about that with that user account, but this one seemed more easily doable here and made more sense to keep it together with this one since we already were using this bit of code. Thanks again if you can get me past this hurdle. I've done pretty well setting this up myself using your same approach. I'm glad it looks like my only remaining question to emulate this will be what I think/hope will be a pretty simple code tweak for you to show me how to pull the post author username.

#2505943

Hello,

It is a custom codes issue, please provide a test site with the same problem, also point out:
- The problem page URL(Where I can test the post form in frontend)
- Where I can edit your custom PHP codes

I need a live website to test and debug, thanks

#2507611

The Freelancer page titling issue has been resolved, so those CRED page titles won't show on future tests.

Here's a test Freelancer with the page title correctly done.

hidden link

So now we just need this Board Vote title issue. You can see that my test votes that are displaying at the bottom of the Freelancer page are showing with the title:

[Test Freelancer 99] Board Vote –

We just want it to show

[Test Freelancer 99] Board Vote – username of Board Member submitting the vote form

#2507831

Thanks for the details, I am checking it in your website, will update here if find anything

#2507833

I have tried the credentials you provided above:
https://toolset.com/forums/topic/i-have-one-question-for-the-other-system/#post-2506679

But get below error message:

ERROR: Incorrect Username or Password
0 attempt(s) left

Please check it, make sure it is a valid admin account, then update here.

#2507869

Please set up another private response and I can send credentials with a different password. Sorry about that.

#2507915

Private message box enabled

#2509483

Your test site is quite slow, it is hard to test and debug in it.

I have done below modifications in your website:
1) Edit the custom codes snippet "board-vote-title"
hidden link
Change the codes to below:

add_action('cred_save_data', function($post_id, $form_data) {
  
  if ($form_data['id']==7956) { // speccific post form ID

    $parent_freelancer_id = toolset_get_related_post($post_id, 'freelancer-board-vote', 'parent', array('post_status'=>array('publish', 'pending')));
    $parent_freelancer_title = get_the_title($parent_freelancer_id);
    $current_user = wp_get_current_user();
    $name = $current_user->user_login;
    $post_title = sprintf('[%1$s] Board Vote - [%2$s]', $parent_freelancer_title, $name);
    $slug = sanitize_title($post_title);
    wp_update_post(array(
      'ID'=>$post_id, 
      'post_title'=>$post_title,
      'post_name' => $slug
    ));
  }
},10, 2);

add_filter( 'toolset_accepted_post_statuses_for_api', static function( $accepted_post_statuses ) {
    if ( is_array( $accepted_post_statuses ) ) { // just for safety...
        $accepted_post_statuses[] = 'pending';
    }
    return $accepted_post_statuses;
} );

Please test again, check if it is what you want.

More helps:
https://developer.wordpress.org/reference/functions/wp_get_current_user/
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_post
https://toolset.com/documentation/programmer-reference/types-api-filters/#toolset_accepted_post_statuses_for_api

#2509855

Awesome! It works. Is it safe to remove the [ ] surrounding the applicant name and the board member username in the title?

It's currently coded as

$post_title = sprintf('[%1$s] Board Vote - [%2$s]', $parent_freelancer_title, $name);

But that looks to me like the brackets are needed. No big deal either way. I just thought I'd ask in case it is easy to remove them. Don't worry about it if it is difficult to remove them.

Site slowness: That's something I'm going to have to work on with this site and the other recent sites I've built with lots of Toolset support assistance. These sites all have huge amounts of advanced functionality built into them requiring many different plugins to achieve, not just everything with Toolset. I previously had these sites in Drupal but am trying to migrate everything to WordPress because the existence of your plugin now allows that. But it's taking a lot of plugins to duplicate all the functionality needed for each site. So I next have a lot to learn about improving performance on seriously loaded WordPress sites. I just want to get all these projects across the finish line to launch them first. Then I'll work on making them faster.

Getting this board voting system achieved with Toolset is the last thing needed with that site and then I still have some work to do on the bike riding club site to get all its functionality done. Thanks HUGELY for the assist again.

#2510085

Yes, it is safe to remove those "[]" characters.

#2510087

My issue is resolved now. Thank you! I removed the [ ] characters and tested and all worked. Great job.