New query safety function for empty post__in
This was causing untold issues...
This commit is contained in:
parent
8ced61b98f
commit
bed9852de1
@ -109,7 +109,7 @@ if ( ! function_exists( 'fictioneer_api_get_story_node' ) ) {
|
||||
array(
|
||||
'post_type' => 'fcn_chapter',
|
||||
'post_status' => 'publish',
|
||||
'post__in' => $data['chapter_ids'],
|
||||
'post__in' => fictioneer_post__in( $data['chapter_ids'] ),
|
||||
'ignore_sticky_posts' => true,
|
||||
'orderby' => 'post__in',
|
||||
'posts_per_page' => -1,
|
||||
|
@ -878,7 +878,7 @@ if ( ! function_exists( 'fictioneer_get_chapter_list_items' ) ) {
|
||||
$hide_icons = fictioneer_get_field( 'fictioneer_story_hide_chapter_icons', $story_id ) || get_option( 'fictioneer_hide_chapter_icons' );
|
||||
|
||||
$query_args = array(
|
||||
'post__in' => $data['chapter_ids'], // Only visible and published
|
||||
'post__in' => fictioneer_post__in( $data['chapter_ids'] ), // Only visible and published
|
||||
'post_type' => 'fcn_chapter',
|
||||
'orderby' => 'post__in',
|
||||
'posts_per_page' => -1,
|
||||
|
@ -305,7 +305,7 @@ if ( ! function_exists( 'fictioneer_add_epub_chapters' ) ) {
|
||||
$query_args = array(
|
||||
'post_type' => 'fcn_chapter',
|
||||
'post_status' => 'publish',
|
||||
'post__in' => $chapters,
|
||||
'post__in' => fictioneer_post__in( $chapters ),
|
||||
'orderby' => 'post__in',
|
||||
'posts_per_page' => -1,
|
||||
'update_post_term_cache' => false, // Improve performance
|
||||
|
@ -981,7 +981,7 @@ function fictioneer_shortcode_chapter_list( $attr ) {
|
||||
$query_args = array(
|
||||
'post_type' => 'fcn_chapter',
|
||||
'post_status' => 'publish',
|
||||
'post__in' => $chapters,
|
||||
'post__in' => fictioneer_post__in( $chapters ),
|
||||
'ignore_sticky_posts' => true,
|
||||
'orderby' => 'post__in', // Preserve order from meta box
|
||||
'posts_per_page' => -1, // Get all chapters (this can be hundreds)
|
||||
|
@ -176,7 +176,7 @@ if ( ! function_exists( 'fictioneer_get_story_data' ) ) {
|
||||
array(
|
||||
'status' => 'approve',
|
||||
'post_type' => 'fcn_chapter',
|
||||
'post__in' => $old_data['chapter_ids'],
|
||||
'post__in' => fictioneer_post__in( $old_data['chapter_ids'] ),
|
||||
'count' => true,
|
||||
'update_comment_meta_cache' => false
|
||||
)
|
||||
@ -228,11 +228,11 @@ if ( ! function_exists( 'fictioneer_get_story_data' ) ) {
|
||||
}
|
||||
|
||||
// Query chapters
|
||||
$chapters = new WP_Query(
|
||||
$chapters = empty( $chapters ) ? $chapters : new WP_Query(
|
||||
array(
|
||||
'post_type' => 'fcn_chapter',
|
||||
'post_status' => 'publish',
|
||||
'post__in' => $chapters,
|
||||
'post__in' => fictioneer_post__in( $chapters ),
|
||||
'ignore_sticky_posts' => true,
|
||||
'orderby' => 'post__in', // Preserve order from meta box
|
||||
'posts_per_page' => -1, // Get all chapters (this can be hundreds)
|
||||
@ -241,7 +241,7 @@ if ( ! function_exists( 'fictioneer_get_story_data' ) ) {
|
||||
);
|
||||
|
||||
// Count chapters and words
|
||||
if ( $chapters->have_posts() ) {
|
||||
if ( ! empty( $chapters ) && $chapters->have_posts() ) {
|
||||
foreach ( $chapters->posts as $chapter ) {
|
||||
// This is about 50 times faster than using a meta query lol
|
||||
if ( ! fictioneer_get_field( 'fictioneer_chapter_hidden', $chapter->ID ) ) {
|
||||
@ -260,7 +260,7 @@ if ( ! function_exists( 'fictioneer_get_story_data' ) ) {
|
||||
$comment_args = array(
|
||||
'status' => 'approve',
|
||||
'post_type' => 'fcn_chapter',
|
||||
'post__in' => $chapter_ids,
|
||||
'post__in' => fictioneer_post__in( $chapter_ids ),
|
||||
'count' => true,
|
||||
'update_comment_meta_cache' => false
|
||||
);
|
||||
@ -1739,4 +1739,25 @@ function fictioneer_delete_my_account() {
|
||||
return false;
|
||||
}
|
||||
|
||||
// =============================================================================
|
||||
// POST__IN SAFETY CHECK
|
||||
// =============================================================================
|
||||
|
||||
/**
|
||||
* Returns the given array or an array with a single zero element if empty
|
||||
*
|
||||
* Prevents an array from being empty, which is useful for 'post__in' query
|
||||
* arguments that cannot deal with empty arrays.
|
||||
*
|
||||
* @since Fictioneer 5.6.0
|
||||
*
|
||||
* @param array $array The input array to check.
|
||||
*
|
||||
* @return array The original array or [0].
|
||||
*/
|
||||
|
||||
function fictioneer_post__in( $array ) {
|
||||
return empty( $array ) ? [0] : $array;
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -122,7 +122,7 @@ function fictioneer_request_story_comments() {
|
||||
array(
|
||||
'status' => 'approve',
|
||||
'post_type' => ['fcn_chapter'],
|
||||
'post__in' => $chapter_ids,
|
||||
'post__in' => fictioneer_post__in( $chapter_ids ),
|
||||
'number' => $comments_per_page,
|
||||
'paged' => $page,
|
||||
'meta_query' => array(
|
||||
|
@ -55,7 +55,7 @@ function fictioneer_post_featured_list( $post_id ) {
|
||||
$query_args = array(
|
||||
'post_type' => 'any',
|
||||
'post_status' => 'publish',
|
||||
'post__in' => $featured,
|
||||
'post__in' => fictioneer_post__in( $featured ),
|
||||
'orderby' => 'post__in',
|
||||
'posts_per_page' => -1,
|
||||
'no_found_rows' => true // Improve performance
|
||||
|
@ -258,7 +258,7 @@ function fictioneer_ajax_get_finished_list() {
|
||||
$list_items = fictioneer_get_card_list(
|
||||
'story',
|
||||
array(
|
||||
'post__in' => $post_ids,
|
||||
'post__in' => fictioneer_post__in( $post_ids ),
|
||||
'paged' => $page,
|
||||
'order' => $order
|
||||
),
|
||||
|
@ -417,7 +417,7 @@ function fictioneer_ajax_get_follows_list() {
|
||||
$list_items = fictioneer_get_card_list(
|
||||
'story',
|
||||
array(
|
||||
'post__in' => $post_ids,
|
||||
'post__in' => fictioneer_post__in( $post_ids ),
|
||||
'paged' => $page,
|
||||
'order' => $order
|
||||
),
|
||||
|
@ -187,7 +187,7 @@ function fictioneer_ajax_get_reminders_list() {
|
||||
$list_items = fictioneer_get_card_list(
|
||||
'story',
|
||||
array(
|
||||
'post__in' => $post_ids,
|
||||
'post__in' => fictioneer_post__in( $post_ids ),
|
||||
'paged' => $page,
|
||||
'order' => $order
|
||||
),
|
||||
|
@ -55,7 +55,7 @@ if ( ! empty( $items ) ) {
|
||||
array(
|
||||
'post_type' => 'any',
|
||||
'post_status' => 'publish',
|
||||
'post__in' => $items,
|
||||
'post__in' => fictioneer_post__in( $items ),
|
||||
'ignore_sticky_posts' => true,
|
||||
'orderby' => 'modified',
|
||||
'posts_per_page' => -1,
|
||||
@ -95,7 +95,7 @@ if ( ! empty( $items ) ) {
|
||||
$chapter_query_args = array(
|
||||
'post_type' => 'fcn_chapter',
|
||||
'post_status' => 'publish',
|
||||
'post__in' => $chapter_ids,
|
||||
'post__in' => fictioneer_post__in( $chapter_ids ),
|
||||
'posts_per_page' => -1,
|
||||
'update_post_term_cache' => false, // Improve performance
|
||||
'no_found_rows' => true // Improve performance
|
||||
@ -129,7 +129,7 @@ if ( ! empty( $items ) ) {
|
||||
$comment_args = array(
|
||||
'post_type' => 'fcn_chapter',
|
||||
'status' => 1,
|
||||
'post__in' => $processed_ids,
|
||||
'post__in' => fictioneer_post__in( $processed_ids ),
|
||||
'count' => true,
|
||||
'update_comment_meta_cache' => false // Improve performance
|
||||
);
|
||||
|
@ -102,7 +102,7 @@ $is_sticky = FICTIONEER_ENABLE_STICKY_CARDS &&
|
||||
$chapter_query_args = array(
|
||||
'post_type' => 'fcn_chapter',
|
||||
'post_status' => 'publish',
|
||||
'post__in' => $chapter_ids,
|
||||
'post__in' => fictioneer_post__in( $chapter_ids ),
|
||||
'posts_per_page' => -1,
|
||||
'no_found_rows' => true, // Improve performance
|
||||
'update_post_term_cache' => false // Improve performance
|
||||
|
@ -55,7 +55,7 @@ if ( ! empty( $args['featured_list'] ) ) {
|
||||
$chapter_query_args = array(
|
||||
'post_type' => 'fcn_chapter',
|
||||
'post_status' => 'publish',
|
||||
'post__in' => $query_chapter_ids,
|
||||
'post__in' => fictioneer_post__in( $query_chapter_ids ),
|
||||
'posts_per_page' => -1,
|
||||
'update_post_term_cache' => false // Improve performance
|
||||
);
|
||||
@ -98,7 +98,7 @@ if ( ! empty( $args['featured_list'] ) ) {
|
||||
get_comments(
|
||||
array(
|
||||
'post_type' => 'fcn_chapter',
|
||||
'post__in' => $query_chapter_ids,
|
||||
'post__in' => fictioneer_post__in( $query_chapter_ids ),
|
||||
'status' => 1,
|
||||
'count' => true,
|
||||
'update_comment_meta_cache' => false
|
||||
|
@ -29,7 +29,7 @@
|
||||
$query_args = array(
|
||||
'post_type' => 'fcn_chapter',
|
||||
'post_status' => 'publish',
|
||||
'post__in' => $args['post_ids'],
|
||||
'post__in' => fictioneer_post__in( $args['post_ids'] ),
|
||||
'order' => $args['order'] ?? 'desc',
|
||||
'orderby' => $args['orderby'] ?? 'date',
|
||||
'posts_per_page' => $args['count'],
|
||||
|
@ -30,7 +30,7 @@
|
||||
$query_args = array(
|
||||
'post_type' => 'fcn_chapter',
|
||||
'post_status' => 'publish',
|
||||
'post__in' => $args['post_ids'],
|
||||
'post__in' => fictioneer_post__in( $args['post_ids'] ),
|
||||
'orderby' => $args['orderby'] ?? 'date',
|
||||
'order' => $args['order'] ?? 'desc',
|
||||
'posts_per_page' => $args['count'],
|
||||
|
@ -25,7 +25,7 @@
|
||||
$query_args = array(
|
||||
'post_type' => 'post',
|
||||
'post_status' => 'publish',
|
||||
'post__in' => $args['post_ids'],
|
||||
'post__in' => fictioneer_post__in( $args['post_ids'] ),
|
||||
'has_password' => false,
|
||||
'orderby' => 'date',
|
||||
'order' => 'DESC',
|
||||
|
@ -29,7 +29,7 @@ $show_taxonomies = ! get_option( 'fictioneer_hide_taxonomies_on_recommendation_c
|
||||
$query_args = array (
|
||||
'post_type' => 'fcn_recommendation',
|
||||
'post_status' => 'publish',
|
||||
'post__in' => $args['post_ids'],
|
||||
'post__in' => fictioneer_post__in( $args['post_ids'] ),
|
||||
'orderby' => $args['orderby'] ?? 'date',
|
||||
'order' => $args['order'] ?? 'desc',
|
||||
'posts_per_page' => $args['count'],
|
||||
|
@ -30,7 +30,7 @@ $show_taxonomies = ! get_option( 'fictioneer_hide_taxonomies_on_recommendation_c
|
||||
$query_args = array (
|
||||
'post_type' => 'fcn_recommendation',
|
||||
'post_status' => 'publish',
|
||||
'post__in' => $args['post_ids'],
|
||||
'post__in' => fictioneer_post__in( $args['post_ids'] ),
|
||||
'orderby' => $args['orderby'] ?? 'date',
|
||||
'order' => $args['order'] ?? 'desc',
|
||||
'posts_per_page' => $args['count'],
|
||||
|
@ -30,7 +30,7 @@ $show_taxonomies = ! get_option( 'fictioneer_hide_taxonomies_on_story_cards' );
|
||||
$query_args = array(
|
||||
'post_type' => 'fcn_story',
|
||||
'post_status' => 'publish',
|
||||
'post__in' => $args['post_ids'],
|
||||
'post__in' => fictioneer_post__in( $args['post_ids'] ),
|
||||
'orderby' => $args['orderby'],
|
||||
'order' => $args['order'] ?? 'desc',
|
||||
'posts_per_page' => $args['count'],
|
||||
|
@ -27,7 +27,7 @@
|
||||
$query_args = array(
|
||||
'post_type' => 'fcn_story',
|
||||
'post_status' => 'publish',
|
||||
'post__in' => $args['post_ids'],
|
||||
'post__in' => fictioneer_post__in( $args['post_ids'] ),
|
||||
'orderby' => $args['orderby'],
|
||||
'order' => $args['order'] ?? 'desc',
|
||||
'posts_per_page' => $args['count'],
|
||||
|
@ -33,7 +33,7 @@ $card_counter = 0;
|
||||
$query_args = array(
|
||||
'post_type' => 'fcn_story',
|
||||
'post_status' => 'publish',
|
||||
'post__in' => $args['post_ids'],
|
||||
'post__in' => fictioneer_post__in( $args['post_ids'] ),
|
||||
'meta_key' => 'fictioneer_chapters_added',
|
||||
'orderby' => 'meta_value',
|
||||
'order' => $args['order'] ?? 'desc',
|
||||
|
@ -35,7 +35,7 @@ $card_counter = 0;
|
||||
$query_args = array(
|
||||
'post_type' => 'fcn_story',
|
||||
'post_status' => 'publish',
|
||||
'post__in' => $args['post_ids'],
|
||||
'post__in' => fictioneer_post__in( $args['post_ids'] ),
|
||||
'meta_key' => 'fictioneer_chapters_added',
|
||||
'orderby' => 'meta_value',
|
||||
'order' => $args['order'] ?? 'desc',
|
||||
|
@ -31,7 +31,7 @@
|
||||
$query_args = array (
|
||||
'post_type' => $args['type'],
|
||||
'post_status' => 'publish',
|
||||
'post__in' => $args['post_ids'],
|
||||
'post__in' => fictioneer_post__in( $args['post_ids'] ),
|
||||
'order' => $args['order'] ?? 'DESC',
|
||||
'orderby' => $args['orderby'] ?? 'date',
|
||||
'posts_per_page' => $args['count'] ?? 8,
|
||||
|
@ -143,7 +143,7 @@ $disable_folding = fictioneer_get_field( 'fictioneer_story_disable_collapse' );
|
||||
array(
|
||||
'post_type' => 'fcn_chapter',
|
||||
'post_status' => 'publish',
|
||||
'post__in' => $chapters,
|
||||
'post__in' => fictioneer_post__in( $chapters ),
|
||||
'ignore_sticky_posts' => true,
|
||||
'orderby' => 'post__in', // Preserve order from meta box
|
||||
'posts_per_page' => -1, // Get all chapters (this can be hundreds)
|
||||
|
@ -124,7 +124,7 @@ do_action( 'rss_tag_pre', 'rss2' );
|
||||
?>
|
||||
|
||||
<?php
|
||||
if ( $chapters ) {
|
||||
if ( ! empty( $chapters ) ) {
|
||||
// Reverse to get latest first
|
||||
$chapters = array_reverse( $chapters );
|
||||
|
||||
|
@ -38,7 +38,7 @@
|
||||
$raw_query_args = array (
|
||||
'post_type' => 'any',
|
||||
'post_status' => 'publish',
|
||||
'post__in' => $featured_list,
|
||||
'post__in' => fictioneer_post__in( $featured_list ),
|
||||
'ignore_sticky_posts' => 1,
|
||||
'posts_per_page' => -1,
|
||||
'no_found_rows' => true // Improve performance
|
||||
@ -63,7 +63,7 @@
|
||||
// Prepare paginated featured query
|
||||
$query_args = array (
|
||||
'post_type' => 'any',
|
||||
'post__in' => $featured_list,
|
||||
'post__in' => fictioneer_post__in( $featured_list ),
|
||||
'ignore_sticky_posts' => 1,
|
||||
'orderby' => 'modified',
|
||||
'order' => 'DESC',
|
||||
|
@ -164,7 +164,7 @@ $tabs[ $current_tab ]['classes'][] = '_current';
|
||||
$list_items = fictioneer_get_card_list(
|
||||
'story',
|
||||
array(
|
||||
'post__in' => $tabs[ $current_tab ]['post_ids'],
|
||||
'post__in' => fictioneer_post__in( $tabs[ $current_tab ]['post_ids'] ),
|
||||
'paged' => $current_page,
|
||||
'order' => $order
|
||||
),
|
||||
|
Loading…
x
Reference in New Issue
Block a user