|
Nested repeatable field groups in a View (that uses info from a parent post)
Started by: John
in: Toolset Professional Support
Quick solution available
Problem: I have a nested repeatable field group (RFG) structure inside a custom post type. I also have another child post type of that main custom post type. On the child post template, I would like to display information from the RFGs. I can display information from the main RFG, but not the nested RFGs.
Solution: Check to be sure the correct RFG type is selected in the View's Content Selection panel.
|
|
2 |
6 |
4 years, 3 months ago
Christian Cox
|
|
Display related post information after adding a favorite post with Favorites plugin
Started by: kayser
in: Toolset Professional Support
Quick solution available
Problem: I have 3 custom post types - Artists, Books, and Works on Paper. I have two one-to-many (O2M) relationships: Artists-Books where Artist is parent and Book is child, and Artists-Works On Paper where Artist is parent and Work on Paper is child. I'm using the Favorites plugin to allow my site visitors to add favorite Books and favorite Works on Paper. In the list of favorite posts, I would like to display information about the related Artist.
Solution: The best way to handle this is to use the Favorites plugin's filters API to filter the favorites list HTML. You can use the Toolset Post Relationships API toolset_get_related_posts to get information from related posts in that filter callback:
/**
* Toolset Support
* Filter the Favorites list information to display related Artiste info
* Currently supports Livres and Oeuvres Sur Papiers post types for Favorites
* Extendable by adding a case statement for new post type / relationship slug
* https://toolset.com/forums/topic/find-related-custom-post-type/
*/
add_filter( 'favorites/list/listing/html', 'custom_favorites_listing_html', 10, 4 );
function custom_favorites_listing_html($html, $markup_template, $post_id, $list_options)
{
// relationship slugs per favorite post type
$post_type = get_post_type( $post_id );
switch($post_type) {
case "livre":
$rel_slug = "livre_artiste";
break;
case "oeuvre-sur-papier":
$rel_slug = "oeuvre-sur-papier-artiste";
break;
default:
return $html;
};
// Get related posts with Toolset post relationships API
$children_args = [
'query_by_role' => 'parent',
'role_to_return' => 'child'
];
$children = toolset_get_related_posts( $post_id, $rel_slug, $children_args);
// Build a string of related post titles, separated by a comma,
// and concatenate it into response HTML, then return it
$child_titles = [];
if( $children && count( $children ) > 0 ) {
foreach( $children as $child ){
$child_titles[]= get_the_title($child);
}
return $html . implode(',', $child_titles);
}
// in case no related posts are found, return the default HTML
return $html;
}
Relevant Documentation:
https://favoriteposts.com/
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts
|
|
2 |
15 |
4 years, 3 months ago
kayser
|
|
Trying to count childeren of a parent
Started by: wesselK
in: Toolset Professional Support
Quick solution available
Problem: I would like to create a custom shortcode that displays the number of child posts for the current parent post. I'm referencing an older ticket but it does not seem to work as expected.
Solution: Instead of the _wpcf_belongs_slug_id postmeta key, you must use the new post relationships API with post relationships created in Types 3.0+. A custom shortcode solution is available.
add_shortcode( 'tssupp-connections', function( $atts = [] ){
// provide defaults
$atts = shortcode_atts(
array(
'relationship' => '',
),
$atts
);
global $post;
$count = 0;
$relationship = toolset_get_relationship( $atts['relationship'] );
if ( $relationship ) {
$parent = $relationship['roles']['parent']['types'][0];
$child = $relationship['roles']['child']['types'][0];
$type = $post->post_type;
$origin = ( $parent == $type ) ? 'parent' : 'child';
// Get connected posts
$connections = toolset_get_related_posts( $post->ID, $atts['relationship'], array(
'query_by_role' => $origin,
'role_to_return' => 'other',
'need_found_rows' => true )
);
$count = $connections['found_rows'];
}
return $count;
});
Use it like this:
Number of children: [tssupp-connections relationship="project-task"][/tssupp-connections]
Relevant Documentation:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts
|
|
2 |
3 |
4 years, 3 months ago
wesselK
|
|
Relevanssi – repeatable custom field
Started by: hispavista-s.l.E
in: Toolset Professional Support
|
|
2 |
4 |
4 years, 3 months ago
Waqar
|
|
Post Navigation Based on One to Many Relationship
Started by: Jaime
in: Toolset Professional Support
|
|
3 |
20 |
4 years, 4 months ago
Jaime
|
|
Retrieve Custom Field from a CPT Relationship outside of the Repeater Field Grp
Started by: saint
in: Toolset Professional Support
|
|
2 |
5 |
4 years, 4 months ago
saint
|
|
Filtering custom post a in archive b
Started by: Dido
in: Toolset Professional Support
|
|
2 |
7 |
4 years, 4 months ago
Dido
|
|
Calling repeating field group with multiple field values in a post loop
Started by: craigM-12
in: Toolset Professional Support
Quick solution available
Problem: I would like to access the fields in a RFG within the loop of the parent post type.
Solution: You can use a View of RFGs with a post relationship filter to loop over RFGs, or you can use the post relationships API to query related posts. Then use the Types Render Field API to render individual fields from each RFG iteration.
|
|
3 |
5 |
4 years, 4 months ago
stephaneb-7
|
|
Setting up City and State for Archive Search Pages
Started by: Charlie
in: Toolset Professional Support
|
|
2 |
4 |
4 years, 4 months ago
Christian Cox
|
|
City does not appear in custom search post relationship filters
Started by: guillaumeT-3
in: Toolset Professional Support
Quick solution available
Problem: I have a custom search View with post relationship filters for City and State, but some Cities never appear in the filters.
Solution: Be sure to provide default options for all search filters like number of bedrooms and number of bathrooms, otherwise, Cities without matching Properties will never appear in the filter options.
|
|
2 |
7 |
4 years, 4 months ago
guillaumeT-3
|
|
Paid membership pro show membership level on frontend with Toolset block view
Started by: MarcoS3712
in: Toolset Professional Support
|
|
2 |
7 |
4 years, 4 months ago
MarcoS3712
|
|
Repeatable field inside search view
Started by: wesselK
in: Toolset Professional Support
Quick solution available
Problem: I would like to display a list of repeatable field groups (RFG) inside the results of a custom search View.
Solution: Use the legacy Views editor to build the nested View, then insert it in the loop of the block editor View using a shortcode.
|
|
2 |
3 |
4 years, 4 months ago
wesselK
|
|
I need help setting up
Started by: yairF
in: Toolset Professional Support
|
|
2 |
21 |
4 years, 4 months ago
Christian Cox
|
|
meta_query on toolset_get_related_posts does not work with radio button values
Started by: suhelaK
in: Toolset Professional Support
|
|
2 |
16 |
4 years, 4 months ago
Minesh
|
|
Creating a view to display related post content is not working
Started by: michaelB-44
in: Toolset Professional Support
|
|
2 |
6 |
4 years, 4 months ago
Christian Cox
|