Skip Navigation

[Closed] Custom code not working with snippet

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
- 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/Karachi (GMT+05:00)

This topic contains 1 reply, has 2 voices.

Last updated by Waqar 1 year, 3 months ago.

Assisted by: Waqar.

Author
Posts
#2540521
Featured.png

I have custom code code called "featuredimage" as follows :

toolset_snippet_security_check() or die('Direct access is not allowed');

add_action('cred_save_data', 'set_image_as_featured', 10, 2);
function set_image_as_featured($post_id, $form_data)
{
// if a specific form
if ($form_data['id'] == 4856 or 610) {
if (isset($_POST['wpcf-gallery'])) {
$image = $_POST['wpcf-gallery'][0];
// Save the first image as featured image
set_post_thumbnail($post_id, attachment_url_to_postid($image));
}

$people_gen_field = $_POST['person']["PL"]; //get value of 'person' field in array
$related_id = $_POST['relatedperson']['RLPL'];
$delperson = array_values(array_diff($related_id, $people_gen_field));
$addperson = array_values(array_diff($people_gen_field, $related_id));
$arrlength = count($people_gen_field);
$addpersonlength = count($addperson);
$arrrelatedlength = count($delperson);
$arrrelid = count($related_id);

disconnect_posts($delperson, $arrrelatedlength, $post_id);
disconnect_all_post($people_gen_field,$related_id, $arrrelid, $post_id);
connect_posts($addperson, $addpersonlength, $post_id);
connect_posts($people_gen_field, $arrlength, $post_id);

$location_gen_field = $_POST['location']["LC"]; //get value of 'location' field in array
$arrlength = count($location_gen_field);
if (!empty($location_gen_field)) {
$x = 0;
do {
// Connect it in a relationship between journal post and person
toolset_connect_posts('journal-location', $post_id, $location_gen_field[$x]);
$x++;
} while ($x < $arrlength);
//var_dump ($location_gen_field);

}
}
}

function disconnect_posts($field, $legth, $post_id){
if (!empty($field)){
$x = 0;
do {
toolset_disconnect_posts('journal-people', $post_id, $field[$x]);
$x++;
} while ($x < $legth);
}
}

function connect_posts($field, $legth, $post_id){
if (!empty($field)){
$x = 0;
do {
toolset_connect_posts('journal-people', $post_id, $field[$x]);
$x++;
} while ($x < $legth);
}
}

function disconnect_all_post($field, $field1,$legth, $post_id){
if ($field == NULL){
$x = 0;
do {
toolset_disconnect_posts('journal-people', $post_id, $field1[$x]);
$x++;
} while ($x < $legth);
}
}

My question is why this custom code only work if I use it on "Custom code snippets" of toolset. Is there any way to make this code work with snippet?

#2541015

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi,

Thank you for contacting us and I'd be happy to assist.

> My question is why this custom code only work if I use it on "Custom code snippets" of toolset. Is there any way to make this code work with snippet?

- I'm afraid, I couldn't fully understand the question.

So, the code snippet is working when added through WP Admin -> Toolset -> Settings -> Custom Code, but what other method are you trying through which it is not working?

Note: The screenshot that you've shared shows that the code snippet's status is 'inactive'.

Can you please share some more details, so that I can suggest the next steps, accordingly?

regards,
Waqar

The topic ‘[Closed] Custom code not working with snippet’ is closed to new replies.