wp query – Custom WP_query in Jnews theme returns thousands of posts


I’m developing a client website with around 53K posts where I switched to the theme Jnews and I’m using a child theme. When I add a simple custom WP_Query to get the latest 3 posts from standard post type ‘post’, the query returns thousands of posts, ignoring my ‘posts_per_page’ => 3. I’ve tried adding the code directly in the parent theme with the same result. If I change the query to get posts from a custom post type with far less posts, it returns 3 with no issues. I tried adding my code to the site’s old theme and it was no issues.

The Jnews support is not that eager to help me because this counts as “custom code” but they didn’t get this issue with my code on their end. I also tried it on a clean WP install with only the parent theme with very few posts in the database and it worked fine.
Any ideas what could be the issue? I get no errors from this, just warnings about slow queries in Query monitor.

My custom code:

$ln_args = array(
            'post_type' => 'post',
            'post_status' => 'publish',
            'posts_per_page' => 3,
            'orderby' => 'publish_date',

        $featured_query = new WP_Query( $ln_args );
        if( $featured_query->have_posts() ) { ?>
            <div class="latestnews-24h">
                    while( $featured_query->have_posts() ){
                        $featured_query->the_post(); ?>
                            <a href="<?php the_permalink(); ?>"><time class="ln24-time"><?php get_the_date('H:s'); ?></time><span class="ln24-title"><?php the_title(); ?></span></a>

Thomas 4 months 2022-09-23T04:03:09-05:00 0 Answers 0 views 0

Leave an answer