Problem: I have a custom post type Destinations and a custom taxonomy Destination Types. I have another custom post type Stories that are child posts of Destinations.
On the Destination Type taxonomy archive page, I would like to show:
- A list of Destinations associated with this Destination Type
- A list of the child Stories of these Destinations
Solution:
- Create a WordPress Archive for the Destination Type taxonomy. Set this archive to only display Destination posts.
- In the Loop Output wpv-loop tags of this WordPress Archive, build the design that corresponds to the Destinations list
- Create a new View of Story posts (I will call this View #1), filtered by post relationship, where the post parent is the current post in the loop.
- In the Loop Output editor, you will build the design the corresponds to the Stories list. For now, you can simply insert a wpv-post-title shortcode in the wpv-loop tags to confirm things are working correctly.
- Create a new View of Destination posts, filtered by Destination Type taxonomy, where the taxonomy term is set by the current archive page. I will call this View #2.
- In the Loop Output editor of View #2, insert View #1 in the wpv-loop tags. Now you have nested View 1 inside View 2, resulting in a list of stories about each destination.
- Insert View #2 in the WordPress Archive, outside the wpv-loop tags, but still inside the wpv-items-found shortcode.
Problem: I want to get the parent post ID. Post relationships created in the new M2M system use dashes in their slugs, but post relationships migrated from the legacy system use underscores in their slugs. I would like to be able to programmatically determine the relationship slug to get related posts, but the naming convention is inconsistent.
Solution: Use the toolset_get_relationship API to inspect new or legacy migrated relationships, and use the toolset_get_related_posts API to get related posts from either migrated or new relationships.
function be_get_parent_id($atts){
//Get current post object and ID
global $post;
$post_id_current = $post->ID;
$a = shortcode_atts( array(
'postid' => $post_id_current,
'parent' => '',
), $atts );
//get post type
$post_id_current = $a['postid'];
$post_type_current = get_post_type($post_id_current);
//The Post relationship slug to check - NOTE THE NEW SYNTAX WITH - HERE
$relationship_to_query = $a['parent']."-".$post_type_current;
//Set the role the other post type has:
$role = "parent";
//Get related posts with new API, if none, it'll return 0, if any, the ID (hence not 0)
// try legacy method, fallback to new method
$related_post = toolset_get_related_post( $post_id_current, array($a['parent'], $post_type_current), $role);
if (! $related_post ){
$related_post = toolset_get_related_post( $post_id_current, $relationship_to_query, $role);
}
return $related_post;
}
add_shortcode( 'be-get-parent-id', 'be_get_parent_id' );
Problem:
How to display parent dropdown select with posts created by current user or post author is current user with CRED form
Solution:
To display parent dropdown select field with posts created by current user or posts author is current user with CRED form, you need to follow the steps shared with the following reply.