Support Forum » User Profile

Forum Replies Created

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • in reply to: Filtering admin view of CPT by Relationship to another CPT #46352
    Christopher AlvarezChristopher Alvarez
    Participant

    Ok, I took a slightly different approach and it appears to be working (filtering the episodes to only those related to the selected show), but the "Show" column is empty.

    add_action( 'parse_query', 'filter_episodes_by_selected_show' );
    function filter_episodes_by_selected_show($query) {
        global $pagenow, $typenow;
    
        if ($typenow == 'episodes' && is_admin() && $pagenow == 'edit.php' && isset($_GET['filter_show']) && $_GET['filter_show'] != '') {
            $show_id = intval($_GET['filter_show']);
            
            if (!empty($show_id)) {
                $query->set('relationship', [
                    'id' => 'episodes-to-shows',
                    'to' => $show_id
                ]);
            }
        }
        return $query;
    }
    in reply to: Empty array when calling get_connected() #42574
    Christopher AlvarezChristopher Alvarez
    Participant

    🤦🏻‍♂️ Wow... of course it was a simple mistake. If the new custom posts are in draft mode, they won't appear in the loop and therefore won't display on the page. Publishing the episode posts was all I needed.

Viewing 2 posts - 1 through 2 (of 2 total)