|
Retrieve content from repeatable field group within repeatable field group (PHP)
Started by: jefM
in: Toolset Professional Support
Quick solution available
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.
Relevant Documentation:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts
|
|
2 |
7 |
3 years, 3 months ago
jefM
|
|
Need a more stable way of hiding CPTs that have no child relations…
Started by: shawnW-3
in: Toolset Professional Support
Quick solution available
Problem: I have a nested View structure that shows parent posts in the outer View and child posts in the nested View. In some cases the parent post has no child posts, and I would like to hide those parent posts in the results. The problem is that the nested child post View is filtered. Is there a conditional that tests whether or not a parent post contains these filtered child posts?
Solution: You can solve this without custom code by restructuring the Views. Instead of displaying the parent post information in the outer View, display the parent post information in the nested child View, inside wpv-items-found but outside wpv-loop. Use the item attribute to display parent post information with any shortcodes in the nested View, since the post context in the nested View is the context of the child posts. The syntax for the item attribute is item="@relationship-slug.parent" in a typical one-to-many (O2M) relationship.
Relevant Documentation:
https://toolset.com/documentation/programmer-reference/views/views-shortcodes/item-attribute/
|
|
3 |
9 |
3 years, 3 months ago
shawnW-3
|
|
Filter to modify the options within the Connect Existing dialog
Started by: David
in: Toolset Professional Support
Quick solution available
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.
Relevant Documentation:
https://developer.wordpress.org/reference/hooks/posts_results/
|
|
2 |
3 |
3 years, 3 months ago
David
|