Answer the question
In order to leave comments, you need to log in
How to add new parameters to WP_Query()?
For example, on a page in a custom template, there is a simple query with a simple loop:
$args = array(
'post_type' => 'objects'
);
$query = new WP_Query( $args );
while ( $query->have_posts() ) {
$query->the_post();
the_title();
}
if(empty($test)==FALSE) {
$args = array(
'posts_per_page' => 2
);
}
Answer the question
In order to leave comments, you need to log in
$args = [
'post_type' => 'objects'
];
// добавляем в массив параметр по условию
if ( $test ) {
$args['posts_per_page'] = 2;
}
// запрос
$query = new WP_Query( $args );
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question