In your code example, you’re mixing two things. With get_posts()
you’ll get an array of posts, which you can use in a custom loop.
$args1 = array(
'post_type' => 'wpcp-events'
'numberposts' => -1,
);
$events = get_posts($args1);
if ( $events ) {
foreach ( $events as $post ) {
setup_postdata( $post ); // make Loop tags available, sets current iteration to global $post
get_template_part('template-parts/event');
}
wp_reset_postdata(); // reset global $post
}
The while (have_posts()) : the_post();
part handles the main loop. If you want to change how it works, you can use pre_get_posts()
. I think this should work,
function change_posts_per_page($query) {
if ( ! is_admin() && $query->is_main_query() && 'wpcp-events' === $query->query['post_type'] ) {
$query->set( 'posts_per_page', 50 );
}
}
add_action( 'pre_get_posts', 'change_posts_per_page' );