The code snippet will check the number of post relations of your post.
In our example, we use “feature-request” post type key,
When a feature request is created or updated, the function will run and check the database for voxel post relations, so that the hidden field “total_myposttype” will get updated with the total number of post relations.
Now you can use this field for sorting, filtering and display.
Count Post Relations for Post Types
Create a number field in your post type called “total_myposttype”
Add a post relation field with the custom key “myposttype”.
Edit the $post_type_config arrays from the code.
No results available
Reset- Filter by
- Filter by
- multiple post types, meta keys and relation keys without duplicating the code
- re-calculates the total number of relations instead of adding +1
- counts only if both related posts are published
- updates the total count when the post is changing it’s status from published
- updates the total count when the post is updated from the WordPress dashboard
No results available
Reset