php - Correct way to list multiple $query->set -



php - Correct way to list multiple $query->set -

what right way list multiple $query->set ? allowed have multiple $query->set "code a" below ? or supposed combine them one? if yes, how combine 3 $query->set code? tried combining them in "code b" below didn't work.

. code a: before combine $query->set

this code goes in functions.php

function featured_category( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( 'category_name', 'new' ); $query->set( 'cat', '-60, -61' ); $query->set( 'posts_per_page', 5 ); } } add_action( 'pre_get_posts', 'featured_category' );

. code b: after combine $query->set

this code goes in functions.php

function featured_category( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( array( 'category_name' => 'new', 'cat' => '-60, -61', 'posts_per_page' => 5) ); } } add_action( 'pre_get_posts', 'featured_category' );

the right way utilize set method (which part of wp_query class) pass 2 parameters - query parameter key , query parameter value. first illustration (code a) right way it.

you can take @ method code here: https://core.trac.wordpress.org/browser/tags/4.0/src/wp-includes/query.php#l2328

p.s. if want exclude multiple categories query, consider using category__not_in query parameters, example:

$query->set( 'category__not_in', array(60, 61) );

for more info category query parameters, check http://codex.wordpress.org/class_reference/wp_query#category_parameters

php wordpress

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -