Skip to content

Commit 31a13ad

Browse files
committed
Fix pre_get_posts conditions
1 parent 10fd399 commit 31a13ad

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

includes/functions/_cpt_and_taxonomies.php

+13-4
Original file line numberDiff line numberDiff line change
@@ -739,16 +739,22 @@ function fictioneer_add_chapter_story_filter_dropdown( $post_type ) {
739739
function fictioneer_filter_chapters_by_story( $query ) {
740740
global $post_type;
741741

742+
// Abort if...
743+
if ( ! function_exists( 'get_current_screen' ) ) {
744+
return;
745+
}
746+
742747
$screen = get_current_screen();
743748

744749
// Make damn sure this is the chapter list table query
745750
if (
746751
! is_admin() ||
747-
empty( $screen ) ||
748-
$screen->id !== 'edit-fcn_chapter' ||
752+
! $query->is_main_query() ||
753+
$query->query_vars['post_type'] === 'fcn_story' ||
749754
$post_type !== 'fcn_chapter' ||
750755
empty( $_GET['filter_story'] ?? 0 ) ||
751-
$query->query_vars['post_type'] === 'fcn_story'
756+
empty( $screen ) ||
757+
$screen->id !== 'edit-fcn_chapter'
752758
) {
753759
return;
754760
}
@@ -765,6 +771,9 @@ function fictioneer_filter_chapters_by_story( $query ) {
765771
// Apply to query
766772
$query->set( 'meta_query', $meta_query );
767773
}
768-
add_action( 'pre_get_posts', 'fictioneer_filter_chapters_by_story' );
774+
775+
if ( is_admin() ) {
776+
add_action( 'pre_get_posts', 'fictioneer_filter_chapters_by_story' );
777+
}
769778

770779
?>

0 commit comments

Comments
 (0)