I'd like to filter the list of "episodes" in the admin edit view so that only episodes related to a selected "show" are returned. I set the filter up, and am passing the show ID in as a parameter, but the query is coming back with zero results.
Here's the code:
add_action( 'pre_get_posts', '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']);
// Query for episodes related to the selected show via MetaBox
$meta_query = array(
array(
'key' => 'episodes-to-shows',
'value' => $show_id,
'compare' => '='
)
);
$query->set('meta_query', $meta_query);
}
}
What am I doing wrong? I've tried a few things aleady:
- Testing on archive page (non-admin) using just the MB_Relationships_API::get_connected() function, but that's returning nothing as well.
- Checking the relationship ID (multiple times... it works to display related info in the main app, but not through the query or API.
- Using a WP_query() instead of the MB API
Is it a timing issue? Why would the API call fail? Is there another way to do this?
`