Custom Loop Query For Search Page

I want to add custom query args to search.php and i made this:

<?php get_header(); ?>

<section id=”primary” class=”content-area”>
<main id=”main” class=”site-main”>

$args = array(
‘posts_per_page’ => 12,
‘order’ => ‘DESC’,

$search_posts = new WP_Query( $args );

if ( $search_posts->have_posts() ) : ?>

<header class=”page-header”>
<h1 class=”page-title”>
<?php printf( esc_html__( ‘Search Results for: %s’, ‘my-theme’ ), ‘<span>’ . get_search_query() . ‘</span>’ ); ?>


while ( $search_posts->have_posts() ) : $search_posts->the_post();

get_template_part( ‘template-parts/content’, ‘search’ );



else :

get_template_part( ‘template-parts/content’, ‘none’ );


wp_reset_postdata(); ?>


<?php get_footer(); ?>

But it not works. It shows all posts.

Read more here:: Custom Loop Query For Search Page

Leave a Reply

Your email address will not be published. Required fields are marked *