Views plugin provides an API, making it easy to display Views output using PHP.
When you ask for help or report issues, make sure to tell us all related information about your View and the data that you want to display using the Views API.
Problem: I have two post types in a one-to-many post relationship. Artists are the parents, and Paintings are the children. In the Artists post type, I have a checkbox custom field. I would like to create a View of Artist posts that only shows Artists with related Paintings. I would also like to include any Artist where the checkbox is checked.
Solution: To accomplish this without custom code, you need 3 Views:
- #1: View of Artists, filtered by checkbox field. Use the legacy Views editor and choose the output type "List with separators". Output the Artists IDs as a comma-separated list.
- #2: View of Artists, filtered by post ID using a shortcode attribute "ids". Design the output as you would like to see on the front-end of the site.
- #3: View of Paintings with no filters. Use the legacy Views editor and choose the output type "List with separators". In the loop, include the post ID of the parent Artist post.
Insert View #2 in your template or page using a shortcode. In the ids attribute, place View #1 and View #3.
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.
Problem:
How to filter parent posts having no child or How to display only parent posts having no children
Solution:
To display the only parent post not having any child post, You need to use the view's query filter: wpv_filter_query in conjunction with the Toolset post-relationship API function where using post-relationship API function toolset_get_related_posts() you will be able to find the child posts based on the specific parent post.