Skip Navigation

[Waiting for user feedback] Toolset-> setting page showing error when running code with ondemand

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
- 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 5 replies, has 1 voice.

Last updated by Minesh 2 days, 11 hours ago.

Assisted by: Minesh.

Author
Posts
#2812939

jum
error.png

I am trying to:
I ran one code in toolset-> custom code. The snippet is on demand and inactive via run now button the code ran fine but after that when I try to open toolset-> settings it showing error. other pages are loading fine.

what I tired:
I have rename the snippet in file manager then the toolset-> setting is loading.

I have run the same code in run always option several times before but it doesn´t cause any issue . I want this code to run only once by manual trigger so I tried on demand option and clicked run away.

`$current_user = wp_get_current_user();

if ($current_user->ID === xxxx) {
error_log('✅ Sync triggered by authorized user ID.');
run_xxxx_location_sync();

} else {
error_log('⛔ Unauthorized sync attempt by user ID: ' . $current_user->ID);
}

function run_xxxx_location_sync() {
error_log('✅ Sync code started running on demand.');

if (!function_exists('toolset_get_related_posts')) {
error_log('❌ Toolset function toolset_get_related_posts not available.');
return;
}

$relationship = 'xxxx-xxxx';
$post_type = 'xxxx';
$taxonomy_slug = 'xxxx';

$batch_size = 100;
$paged = 1;
$processed = 0;
$errors = 0;

do {
$posts = get_posts([
'post_type' => $post_type,
'posts_per_page' => $batch_size,
'paged' => $paged,
'post_status' => 'publish',
'fields' => 'ids',
]);

if (empty($posts)) {
break;
}

foreach ($posts as $post_id) {
$processed++;

$related_parents = toolset_get_related_posts(
$post_id,
$relationship,
'child',
100,
0
);

$terms_to_set = [];
if (!empty($related_parents)) {
foreach ($related_parents as $parent_id) {
$terms = wp_get_post_terms($parent_id, $taxonomy_slug, ['fields' => 'ids']);
if (!empty($terms)) {
$terms_to_set = array_merge($terms_to_set, $terms);
}
}
}

$terms_to_set = array_unique($terms_to_set);

if (!empty($terms_to_set)) {
wp_set_post_terms($post_id, $terms_to_set, $taxonomy_slug);
} else {
$errors++;
}
}

error_log("⏳ Batch {$paged} processed. Total processed: {$processed}");

$paged++;
} while (count($posts) === $batch_size);

error_log("✅ All {$processed} posts processed.");
if ($errors) {
error_log("⚠️ {$errors} posts had no terms to set.");
} else {
error_log("🎉 All posts updated successfully with taxonomy terms.");
}
}`

Please guide me how to fix this issue.

#2813146

Minesh
Supporter

Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

This is a pure custom code and we are not allowed to dig the custom code but still I will try to look at once.

Can you please setup a staging site and send me admin access details and let me see if I have any solution for you.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

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

#2813165

Minesh
Supporter

Languages: English (English )

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

I tried to login using the admin access details you share but its not worknig at this end.

Can you please send me working admin access details.

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

#2813291

Minesh
Supporter

Languages: English (English )

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

Can you please tell me with what code snippet I can test against as well as what is the original code.

As I can see the code you shared and one of the code snippet namely "test" I can see its different code with what you shared with your first post with this ticket.

#2813619

jum

Hi Minesh,

As mentioned the code is in locationupdate-discard2.php in toolset code snippet.

I have gave the post type details in the code comment section for your reference.

Please have a look and let me know , if need further details can you please open private chat.

Thanks in advance

#2814080

Minesh
Supporter

Languages: English (English )

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

I see the issue but can you first update ALL plugins to latest version in order to make sure we are running with latest Toolset plugins as well as other addon plugins.

Also, can you please share FTP/SFTP access details.

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