'post', 'posts_per_page' => $limit_for_mix, 'orderby' => 'date', 'order' => 'DESC', 'post_status' => 'publish', 'cat' => $m_cat, 'date_query' => [ [ 'after' => $rule['target_age'] . ' days ago' ] ] ]; $q = new WP_Query( $args ); if ( $q->have_posts() ) { foreach ( $q->posts as $p ) { if ( $this->is_noindex( $p->ID ) ) { continue; } $inbound = (int) get_post_meta( $p->ID, '_ailm_inbound_count', true ); if ( $inbound >= $target_limit ) { continue; } $final_urls[] = get_permalink( $p->ID ); } } } } $main_pct = 100 - $used_pct; if ( $main_pct > 0 ) { $limit_for_main = ceil( $pool_size * ( $main_pct / 100 ) ); $args = [ 'post_type' => 'post', 'posts_per_page' => $limit_for_main, 'orderby' => 'date', 'order' => 'DESC', 'post_status' => 'publish', 'date_query' => [ [ 'after' => $rule['target_age'] . ' days ago' ] ] ]; if ( $rule['cat_id'] != 0 ) { $args['cat'] = $rule['cat_id']; } $q = new WP_Query( $args ); if ( $q->have_posts() ) { foreach ( $q->posts as $p ) { if ( $this->is_noindex( $p->ID ) ) { continue; } $inbound = (int) get_post_meta( $p->ID, '_ailm_inbound_count', true ); if ( $inbound >= $target_limit ) { continue; } $final_urls[] = get_permalink( $p->ID ); } } } if ( empty( $final_urls ) ) { if ( ! $debug_mode ) { set_transient( $transient_key, 'empty', $cache_seconds ); } return []; } if ($shuffle) { shuffle( $final_urls ); } if ( count( $final_urls ) > $pool_size ) { $final_urls = array_slice( $final_urls, 0, $pool_size ); } if ( ! $debug_mode ) { set_transient( $transient_key, $final_urls, $cache_seconds ); } return $final_urls; } /** * Helper function to check for noindex meta from popular SEO plugins. * * @since 1.0 * @param int $pid The Post ID. * @return bool True if the post is marked as noindex. */ private function is_noindex( $pid ) { // Yoast SEO $yoast_noindex = get_post_meta( $pid, '_yoast_wpseo_meta-robots-noindex', true ); if ( $yoast_noindex == 1 || $yoast_noindex == 2 ) { return true; } // Rank Math $rm_robots = get_post_meta( $pid, 'rank_math_robots', true ); if ( is_array( $rm_robots ) && in_array( 'noindex', $rm_robots ) ) { return true; } return false; } }