Team DNK
Support threads created in the last 30 days: 0
Favorite Forum Topics
This user has no favorite topics.
Forum Topics Created
Status | Topic | Supporter | Voices | Posts | Freshness |
---|---|---|---|---|---|
Fields and Views – Modify Shortcode Output
Started by: Team DNK
in: Toolset Professional Support
Problem: We are needing a way to extend/modify the existing field and view shortcodes. Solution: Toolset View/Types shortcodes are also registered with WP function add_shortcode(), so you can use WP built-in filter hook do_shortcode_tag to apply your custom codes Relevant Documentation: https://developer.wordpress.org/reference/hooks/do_shortcode_tag/ |
2 | 3 | 4 years, 5 months ago | ||
ToolSet Settings Custom Code – How To Define Name In Code.
Started by: Team DNK in: Toolset Professional Support |
2 | 3 | 5 years, 8 months ago | ||
ToolSet Settings Custom Code Missing Description Field
Started by: Team DNK
in: Toolset Professional Support
Problem: Solution: |
2 | 3 | 5 years, 8 months ago | ||
Favorite Posts By Logged In User (Add To / Remove not working properly)
1
2
Started by: Team DNK
in: Toolset Professional Support
Problem: I would like Users to be able to choose certain posts as favorites. They should also be able to remove them from favorites. Solution: Create a CRED form that allows you to modify the posts that can be favorited. Remove all the content from the CRED form and replace it with the following code: [credform class='cred-form cred-keep-original'] [wpv-conditional if="( [toolset_is_favorite id='[wpv-post-id]'] eq '1' )"] [cred_generic_field field='remove-favorite' type='hidden' class=''] { "required":0, "validate_format":0, "default":"1" } [/cred_generic_field] [/wpv-conditional] [cred_field field='form_submit' value='Favorite' urlparam='' class='x-btn x-btn-global mam'] [/credform] Add the following JavaScript to your CRED form's JS panel: jQuery(window).bind("load", function() { jQuery( "form[id^='cred_form_368']").find("input[type='submit']").val(jQuery( "input[name='remove-favorite']").length ? "Remove from Favorites" : "Add to Favorites"); } ) This code will toggle between showing "Add to Favorites" and "Remove from Favorites" as the button name. Add the following PHP to your child theme's functions.php file: add_action('cred_save_data_368', 'sda_user_favorites',10,2); function sda_user_favorites($post_id, $form_data) { if( isset($_REQUEST['remove-favorite']) ) { delete_post_meta($post_id, 'wpcf-favorites', get_current_user_id()); } else { add_post_meta($post_id, 'wpcf-favorites', get_current_user_id(), false); } } /* Favorites shotcode for use as a conditional */ add_shortcode( 'toolset_is_favorite', 'toolset_is_favorite_func'); function toolset_is_favorite_func($atts) { global $wpdb; $post_id = $atts['id']; $user_id = get_current_user_id(); $favorites = $wpdb->get_results( "SELECT * FROM wp_postmeta WHERE meta_key = 'wpcf-favorites' AND post_id = $post_id AND meta_value = $user_id LIMIT 1"); return sizeof($favorites) ? 1 : 0; } Be sure to add the toolset_is_favorite shortcode in Toolset > Settings > Frontend content > 3rd party shortcode arguments. Place the CRED form in a View of posts, or in a Content Template for these posts. Relevant Documentation: https://toolset.com/documentation/programmer-reference/cred-api/#cred_save_data |
3 | 19 | 7 years ago |