Hi Jamal,
You are right about the documentation which only leaves me even more confused because I know the bookmark functionality is working, and the 'remove-favorite' is being created conditionally. Since the 'remove-favorite' field is hidden, I added another checkbox field 'fav' within the conditional group which I can confirm is being created only for posts that have been bookmarked (see all screenshots).
I am implementing bookmark functionality using toolset alone, no other plugins, based on the support thread I linked previously. I understand it is long so if you'd like the short version, please read this or else skip to the next paragraph! I created a repeating custom number field called 'bookmark-id', to store the ID of each user who has bookmarked that post. To create the '+'/'-' bookmark button, I created a form to edit the 'resource' post type, removed everything except the submit button, added the code (as provided by the support exec Christian on the other thread) to create a hidden generic field ('remove-favorite') conditionally for each post if the current post already has the current logged in user's ID in the 'bookmark-id' field. I added the following code to the functions.php file to add or remove the user ID based on the presence or absence of the 'remove-favorite' field.
add_action('cred_save_data_1660', 'toggle_user_favorite_cred',10,2);
add_action('cred_save_data_1606', 'toggle_user_favorite_cred',10,2);
function toggle_user_favorite_cred($post_id, $form_data)
{
if( isset($_REQUEST['remove-favorite']) ) {
delete_post_meta($post_id, 'wpcf-bookmark-id', get_current_user_id());
} else {
add_post_meta($post_id, 'wpcf-bookmark-id', get_current_user_id(), false);
}
}
My guess is that the javascript is changing all the bookmark buttons to '-' because that code was written by Christian to be used on a content template with one bookmark button, not an archive page with multiple ones. So when even one of the bookmark buttons/post-edit forms has the 'remove-favorite' field, all of the buttons are having their values changed. I can sort of confirm that becuase when I remove my user ID from the 'bookmark-id' field in all the posts, I see '+' buttons, but when even one post is bookmarked, I see the 'fav' checkbox field on that post alone but all the buttons now read '-' (see screenshots). Could you help me modify the following JS accordingly to be used in an archive page? It would really help make this bookmark functionality work within toolset without needing any other third party plugins! Thank you for your time Jamal 🙂
jQuery(window).bind("load", function() {
jQuery( "form[id^='cred_form_1606']").find("input[type='submit']").val(jQuery( "input[name='remove-favorite']").length ? "-" : "+");
});