Types plugin lets you easily create relationships between different post types and connect them using GUI controls. You can also connect multiple post types and build many-to-many post relationships.
When you ask for help or report issues, make sure to tell us what you have created so far and the structure that you want to achieve.
Viewing 15 topics - 151 through 165 (of 801 total)
Problem: We have one repeatable field group (RFG) that contains another nested RFG. We would like to build a nested array in PHP that contains information from the nested RFG structure, but we are not able to access custom field values in the nested RFG using the toolset_get_related_posts API and get_post_meta.
Solution: In this case the inner, nested toolset_get_related_posts API call must be updated to query by the current outer RFG's post ID as opposed to querying by the ID of the post containing the RFGs. In the case of the outer RFG, querying by the ID of the post is appropriate, but in the case of the inner RFG, you should query by the ID of the outer RFG since the post relationship is technically established between the two RFGs.
Problem: I am using the Connect Existing dialog to connect existing posts in the post relationship panel of the post editing screen. I have several posts with similar names, so I would like to filter the post titles somehow to include additional identifying information.
Solution: Use a custom code snippet hooked into posts_results to filter these titles:
// Toolset Support Reference: https://toolset.com/forums/topic/filter-to-modify-the-options-within-the-connect-existing-dialog/
// adjust post titles in Connect Existing dialog of relationship editor panel
function ts_filter_connect_existing_titles( $posts, $query ){
$post_types = ['band', 'event']; // slugs of post types
$rel_slugs = ['band-event']; // slugs of post relationships
//We only want to run this if User is searching for related content for specific relationships using the Connect Existing dialog
if ( defined('DOING_AJAX')
&& isset($_REQUEST['action'])
&& $_REQUEST['action']=='types_related_content_action'
&& isset($_REQUEST['relationship_slug'])
&& in_array($_REQUEST['relationship_slug'], $rel_slugs)
&& isset($query->query['post_type'][0])
&& in_array($query->query['post_type'][0], $post_types)
) {
foreach($posts as $post){
// modify the post title as desired here
$post->post_title = 'Test-' . $post->post_title;
}
}
return $posts;
}
add_action( 'posts_results', 'ts_filter_connect_existing_titles', 99, 2 );
You can adjust the post type slugs band and event, as well as the post relationship slug band-event to match your content. This code will manipulate the titles of posts in any of the post types included in the $post_types array, in the Connect Existing dialog for any of the post relationships included in the $rel_slugs array. Modify the post titles however you'd like in the foreach loop. Note that this does not extend search capabilities.
Problem: I have a Form that creates child posts. If the featured image is not provided in the child post Form, I would like to copy the featured image from the parent post into the featured image of the child post.
Solution: If the parent post is not predefined, then you must use the Forms API to copy the parent post's featured image into the child post's featured image since the parent post cannot be determined at the time the Form is loaded. Use the cred_submit_complete API to automate the process. In that callback you can use toolset_get_related_post or toolset_get_related_posts to query the parent post, then get_post_meta to fetch the featured image, then update_post_meta in the child post to set the featured image programmatically.