• i added this to my fuctions to show only posts of type wines to the homepage.

    function home_posts( $query ) {
        if ( $query->is_home() && $query->is_main_query() ) {
            $query->set( 'post_type', 'wines' );
        }
    }
    add_action( 'pre_get_posts', 'home_posts' );

    I also want to do 12 posts per page. I wrote it as below but I get error Warning: Missing argument 2 for WP_Query::set(),

    function home_posts( $query ) {
        if ( $query->is_home() && $query->is_main_query() ) {
            $query->set(array('post_type' => 'wines', 'posts_per_page' => 12));
        }
    }
    add_action( 'pre_get_posts', 'home_posts' );

    What is the correct way to write this?

Viewing 1 replies (of 1 total)
  • Moderator Marius L. J.

    (@clorith)

    Hi,

    You’ll want to set multiple times (you can use the $query->set() call as many times as you need), so in your case you’ll want to do the following

    $query->set( 'post_type' => 'wines' );
    $query->set( 'posts_per_page' => 12 );
Viewing 1 replies (of 1 total)

The topic ‘$query->set with array?’ is closed to new replies.