Code to Display Future Posts is Affecting My Media Library
-
Hi,
I’m currently using the following code in my functions.php file to display scheduled posts for the custom post type “movies”.
//DISPLAY FUTURE POST TYPES add_filter( 'pre_get_posts', 'get_future_posts' ); function get_future_posts( $query ) { if ( is_home() && $query->is_main_query() ) //IF YOU WANT TO INCLUDE CUSTOM POST TYPES $query->set( 'post_type', array( 'post', 'movies' ) ); //INCLUDE POSTS WHOSE STATUS IS BOTH PUBLISHED AND FUTURE $query->set( 'post_status', array( 'publish', 'future' ) ); return $query; } // SHOW FUTURE POSTS SINGLE.PHP function show_future_posts($posts){ global $wp_query, $wpdb; if(is_single() && $wp_query->post_count == 0){ $posts = $wpdb->get_results($wp_query->request); } return $posts; } add_filter('the_posts', 'show_future_posts');
However, while this code works great for what I want it to do, I noticed it for some reason affects my media library. Whenever I go to my media library or try and insert an image through media library it always tells me “No media files found.” even though I know there is. When I remove the code above, it shows me all the images like normal.
Any ideas on how this is being affected and what I can do?
Thank you
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Code to Display Future Posts is Affecting My Media Library’ is closed to new replies.