Problem:
We have two related CPTs - Resources & Resource Items (1 Resource - many Items). Each individual Item has a select field to indicate an associated language.
We present users with a Resources page where they can search on various aspects of Resources and would like to add the ability to search for Resources according to which languages they are associated with via their related Resource Items.
Solution:
Currently, Toolset does not allow to filter a custom post type by custom fields on a related post type. This feature is on our list and will be added in the future, but we still don't know when.
It is worth mentioning that this can be implemented with custom code. It will need custom code to build the filter and another custom code that can use the toolset_get_related_posts function and hook into the view's wpv_filter_query query filter.
Problem: I would like to display a list of custom search tag filters as formatted text links. When a User clicks one of the text links, the search results in the View should update.
Solution: Use the "radio" input type and apply custom CSS to hide the radio button and apply styles to each label element to achieve the text link "pill" effect.
Problem: In my Form, I would like to include a select field with options for each Country, so Users can select their Country of origin when registering for the site.
Solution: Toolset does not include built-in Country select fields, but another User has created a module that includes information for importing such a field. You may import information from that module as a starting point.
Problem: I would like to use a cred-delete-post shortcode to allow my visitors to delete a post on the front-end of the site. This post may be the parent of one or more child posts. When the parent post is deleted, I would like to delete its attachments, and its child posts as well as their attachments.
Solution: Use the 'delete' action in the cred-delete-post shortcode, and customize the following code snippet to work with your post type slugs and post relationship slug.
function delete_post_children($post_id) {
global $wpdb;
$post_type = get_post_type( $post_id );
if ( $post_type == 'products' || $post_type == 'profile') {
$ids = $wpdb->get_col("SELECT ID FROM {$wpdb->posts} WHERE post_parent = $post_id AND post_type = 'attachment'");
foreach ( $ids as $id ) {
wp_delete_attachment($id, true);
}
if(has_post_thumbnail( $post_id )) {
$tn_id = get_post_thumbnail_id( $post_id );
wp_delete_attachment($tn_id, true);
}
if( $post_type == 'profile' ) {
// in this case, we want to force-delete the child product posts as well
$profile_products = toolset_get_related_posts(
$post_id,
'profile-product',
[
'query_by_role' => 'parent',
'role_to_return' => 'child',
'limit' => 10000,
'orderby' => null,
]
);
foreach($profile_products as $profile_product ) {
wp_delete_post( $profile_product, true );
}
}
}
}
add_action('before_delete_post', 'delete_post_children');
Problem: I am using a shortcode from the e2PDF plugin that displays a Types custom field value. However, my field allows multiple instances and I would like to display one specific index of that field. How can I customize the shortcode to work with Types repeating field values?
Solution: Response from e2PDF support: As for now you can try to hook default output with adding filter to your theme functions.php:
add_filter('e2pdf_model_shortcode_e2pdf_wp_response', 'e2pdf_toolset_types_repeater', 10, 3);
function e2pdf_toolset_types_repeater($response, $atts, $value) {
if (isset($atts['key']) && $atts['key'] == 'wpcf-listing-photo' && isset($atts['index'])) {
$id = isset($atts['id']) ? $atts['id'] : false; // Post ID
$index = $atts['index']; // Index attribute
$field = str_replace('wpcf-', '', $atts['key']); // Converting field key to slug needed for Tooset Types
if ($id) {
//php function to render value
$response = types_render_field($field, array("post_id" => $id, "size" => "thumbnail", "index" => $index));
} else {
$response = '';
}
}
return $response;
}
After adding function you must be able to use shortcode as follows:
For correct usage "types_render_field" function must return "empty" value in case index not exists or url for image if image found, so maybe it will be need to add some parameters to "types_render_field". Unfortunately we can't test it on our side as we do not have yet access to Toolset Types plugin.
Problem:
The main issue that I can't get my head around is this.
I will create one course post with only one set of chapters for one course.
Users will not be the author of this post so how can I assign this same post to all users who sign up to my website as seperate posts so i can begin to work on how to capture each user's progress.
Solution:
In my reply to your previous ticket, I talked about assigning a post to a user by making the user the author of that post. A post has only ONE author, so we can't assign a post to multiple users using the author field.
What we can do instead, is creating another custom post type, let's call it "Subscription" or "Enrollment", this post will be linked to the "Course" or the "Chapter" custom post type using a One-to-many relationship, and make the user the post's author. This way, a "Course" or "Chapter" will have multiple "Subscription" posts linked to it. Each "Subscription" post will have an enrolled user as the author.
On the "Course" or "Chapter" post page, we'll use a view that will query "Subscription" posts linked to this "Course" or "Chapter" that are created by the current user. If the user has already an existing post, we will use this post to track to progress. If the user does not have any posts, we can offer him a Toolset Form(may have only the submit button) to let the user enroll in this course/chapter by creating the "Subscription" post. Does it make sense?
Please note that Toolset relationships are only between two custom post types, so we can't have a relationship between Course, Chapter, and Subscription. We can only have it between a Course and a Subscription, or a Chapter and a subscription.