Team DNK
Fils de soutien créés au cours des 30 derniers jours : 0
Sujets de forum favoris
This user has no favorite topics.
Sujets de forum créés
Status | Sujet | Supporter | Voix | Publications | Nouveauté |
---|---|---|---|---|---|
Fields and Views – Modify Shortcode Output
Commencé par : 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 | Il y a 4 années et 4 mois | ||
ToolSet Settings Custom Code – How To Define Name In Code.
Commencé par : Team DNK in: Toolset Professional Support |
2 | 3 | Il y a 5 années et 7 mois | ||
ToolSet Settings Custom Code Missing Description Field
Commencé par : Team DNK
in: Toolset Professional Support
Problem: Solution: |
2 | 3 | Il y a 5 années et 7 mois | ||
Favorite Posts By Logged In User (Add To / Remove not working properly)
1
2
Commencé par : 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 | Il y a 6 années et 10 mois | ||
Control View’s output with Access
1
2
3
Commencé par : Team DNK
in: Toolset Professional Support
Problem: Solution: |
5 | 47 | Il y a 6 années et 11 mois | ||
Views Query Filter based on Access Post Group
1
2
Commencé par : Team DNK in: Toolset Professional Support |
4 | 24 | Il y a 7 années et 6 mois | ||
Add Leading Zeros To Number Field
Commencé par : Team DNK
in: Toolset Professional Support
Problem: I would like to display a number from a custom field in my post with at least 3 digits. If necessary, I would like to pad the number with leading zeros. Solution: Display the custom field using a custom shortcode. This shortcode will append leading zeros if necessary to the display without affecting the value stored in the database. This is helpful because it can be used in various places on the site and it does not break numeric sorting, calculations, or comparisons. /* --------------------------------------------- */ // CUSTOM THREE DIGIT SHORTCODE add_shortcode( 'pad_three_digits', 'my_pad_three_digits_func'); function my_pad_three_digits_func($atts) { $num = $atts['num']; return str_pad($num, 3, '0', STR_PAD_LEFT); } [pad_three_digits num="1"] // 001 [pad_three_digits num="10"] // 010 [pad_three_digits num="100"] // 100 [pad_three_digits num="1000"] // 1000 [pad_three_digits num="[types field='project-number' format='FIELD_VALUE'][/types]"] // outputs a custom field number padded if necessary Relevant Documentation: https://codex.wordpress.org/Shortcode_API |
2 | 7 | Il y a 7 années et 6 mois | ||
Only Want Auto Numbering For New Post, Not When Editing The Post
Commencé par : Team DNK
in: Toolset Professional Support
Problem: I would like to include a custom field value on my Project post type that begins at zero and is incremented for each new post. When I modify an existing post, I do not want the existing auto increment value to change. Solution: /* Auto number Project posts */ add_action( 'save_post', 'auto_number', 100, 3 ); function auto_number( $post_id, $post, $update ) { if ( $post->post_status == 'publish' && $post->post_type == 'project' ) { $project_args = array( 'numberposts' => 2, 'post_type' => 'project', 'orderby' => 'post_date', 'order' => 'DESC' ); $projects = get_posts( $project_args ); // don't update existing auto-numbering $this_id = get_post_meta( $projects[0]->ID, 'wpcf-project-number', true); if ( $this_id ) { return; } $last_id = get_post_meta( $projects[1]->ID, 'wpcf-project-number', true); if ( !$last_id ) { $last_id = 0; } $last_id++; update_post_meta( $post_id, 'wpcf-project-number', $last_id ); } } |
2 | 7 | Il y a 7 années et 6 mois |