Problem: I would like to use a custom field from a related post to generate a dynamic link in the child post template. The Types field shortcode for this field is not returning any value.
Solution: You can use the Types field shortcode to output information from a related post using a special syntax in the "item" attribute, like this:
Problem: I have a one-to-many post relationship between two custom post types. In the template for the child post type, I would like to display "Next" and "Previous" links to paginate between the sibling posts.
Solution: Use a custom shortcode like this example that implements the post relationships API to create pagination links:
// https://toolset.com/forums/topic/next-and-previous-sibling-posts-in-a-one-to-many-post-relationship/
// get a link to the next or previous sibling post in child post content template
// example: [tssupp-next-prev-child current="[wpv-post-id]" step="1" relslug="book-chapter"][/tssupp-next-prev-child]
// current: current post id, step: 1 for next or -1 for previous, relslug: slug of the post relationship
function tssupp_next_prev_child($atts) {
$a = shortcode_atts( array(
'current' => 0,
'step' => '1',
'relslug' => '',
), $atts );
$link = '';
// get all child posts
$relationship_slug = $a['relslug'];
$current_child_id = $a['current'];
$parent_id = toolset_get_related_post( $current_child_id, $relationship_slug );
$sibling_args = array(
'query_by_role'=>'parent',
'limit'=>1000,
'role_to_return'=>'child',
'orderby'=>'title'
);
$siblings = toolset_get_related_posts( $parent_id, $relationship_slug, $sibling_args );
// loop over child posts and get index of the current post
foreach($siblings as $i=>$sibling) {
if( $sibling == $current_child_id ) {
break;
}
}
// increment or decrement index for next or previous sibling
$i += $a['step'];
// create link to next/previous sibling
if(isset($siblings[$i])){
$perm = get_the_permalink( $siblings[$i] );
$title = get_the_title( $siblings[$i] );
$link .= $a['step']=='1' ? "Next: " : "Previous: ";
$link .= "<a href='" . $perm . "'>" . $title . "</a>";
}
// output the link, or empty string if not set
return $link;
}
add_shortcode( 'tssupp-next-prev-child', 'tssupp_next_prev_child' );
You'll use the shortcode like this to generate a "Next" link (if necessary):
Problem: I have created a custom field group and applied it to a custom post type. After migrating my site to a new host, when I edit those custom posts in wp-admin I cannot see the field group. If I open the Screen Options tab, the field group does not appear in the list of available field groups for display.
Solution: This appears to be a server-side caching issue. Resave the field group(s) in Types > Custom Fields > Post fields, flush the object cache using the 3rd-party object cache system controls, and the field group should appear as expected when editing these posts.
Problem:
The user was not able to use the new Divi integration discussed in this article. The new view module for Divi that was included in Toolset Blocks.