How to retrieve $query->set( ‘posts_per_page’, 5) globally?

Question

get_option( 'posts_per_page' ); returns the default number of pages set under Reading
in WordPress.

The function below returns a different number of pages for a custom post type.

function mg_events_posts_per_page( $query ) {
    
    if( $query->is_main_query() && !is_admin() && is_post_type_archive( 'event' ) ) {
        $query->set( 'posts_per_page', '5' );
    }

}
add_action( 'pre_get_posts', 'mg_events_posts_per_pagee' );

How do I retrieve the value for $query->set( 'posts_per_page', '5' ); as a conditional elsewhere similar to get_option( 'posts_per_page' );

Foe example;

if ( $query->set( 'posts_per_page', '5' ) ) { // Do something }

0
Motivated 6 months 2022-02-04T23:05:09-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse