Problem: I would like to add a column to the post list in wp-admin menu for a custom post type. In that column I would like to display the number of child posts in a specific post relationship.
Solution: Custom code is required to do this.
/****************************** ** Adds post relationship column to salons table ******************************/ add_filter( 'manage_edit-salons_columns', 'my_edit_salons_columns' ) ; function my_edit_salons_columns($defaults) { $defaults['child'] = 'Child'; return $defaults; } /****************************** ** Adds data to the post relationship column in salons table ******************************/ add_action( 'manage_salons_posts_custom_column', 'my_manage_salons_columns', 10, 2 ); function my_manage_salons_columns($column_name, $post_id) { if ($column_name == 'child') { $children = toolset_get_related_posts( $post_id, 'salons-shops', 'parent', 1000000, 0, array(), 'post_id', 'child' ); echo sizeof($children); } }
Relevant Documentation:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | 8:00 – 12:00 | - | - |
13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | 13:00 – 17:00 | - | - |
Supporter timezone: America/New_York (GMT-04:00)
This topic contains 2 replies, has 2 voices.
Last updated by 6 years, 6 months ago.
Assisted by: Christian Cox.