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, 10 months ago
wesselK
Display from side by side element not working
Started by: danielM-34
in: Toolset Professional Support
Quick solution available
2
7
4 years, 10 months ago
danielM-34
view search, layout and map custom design
Started by: jakobd-2
in: Toolset Professional Support
Quick solution available
Problem:
How to display Views block search form, search result + map in different places.
Solution:
Here are details steps:
1) Create a page, for example "test-page-1"
Add a view block, display the search form + search result
2) Create another page, for example "test-page-2"
Display three blocks:
- View block, display only search form
- View block, display only the search result
- Map block, "source for the maker" choose above view block
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/maps/maps-shortcodes/#wpv-map-render
2
5
4 years, 10 months ago
jakobd-2