• Resolved Cami MacNamara

    (@webcami)


    Hello,

    I’m needing help with some code. I’m using the following in my functions.php file to limit home page blog posts to 3 in this studiopress theme:

    https://westseattlewordpress.com/shordental/

    //* Limit post number on homepage
    add_action( ‘pre_get_posts’, ‘change_posts_number_home_page’ );
    function change_posts_number_home_page( $query ) {

    if ( is_home() )
    $query->set( ‘posts_per_page’, 3 );

    return $query;
    }

    I just discovered it’s also limiting my number of meteor slides to three – I have 4 slides and settings for 4.

    I’m using this function so the remainder of the site blog pages can have 10 posts showing.

    Can anyone help me manipulate this function to limit the blog posts on the page but NOT the meteor slides? I’m assuming the slides are also POSTS? Please help!

    https://www.ads-software.com/plugins/meteor-slides/

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Josh Leuze

    (@jleuze)

    Hi, yes the slides are a custom post type. The query for the slideshow is pretty well insulated from other queries on the page, but the code you posted will target all the queries on the page. You can use is_main_query function to limit this to just the main query, like this:

    //* Limit post number on homepage
    add_action( 'pre_get_posts', 'change_posts_number_home_page' );
    function change_posts_number_home_page( $query ) {
    
    if ( is_home() && $query->is_main_query() )
    $query->set( 'posts_per_page', 3 );
    
    return $query;
    }
    Thread Starter Cami MacNamara

    (@webcami)

    THANK YOU! THANK YOU! THANK YOU!

    Plugin Author Josh Leuze

    (@jleuze)

    You’re welcome!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Limiting # blog posts on homepage and it's effecting # of slides, too. Pls HELP!’ is closed to new replies.