Wednesday, January 25, 2023
HomeWordPress Developmentplugin improvement - filter on get_posts effectively

plugin improvement – filter on get_posts effectively


I’ve posts with the next classes:

A class that could be a 12 months(2017,2018…2022), a class that’s sort:(worldwide,Europe, native)

I’m making an attempt to offer customers within the frontend superior search potential they’ve two multislect dropdown, they’ll choose a 12 months or a number of. and a sort. (each of those are technically classes)

For instance “choose submit from cat 2017 or cat 2018 AND which are (cat=Europe or cat=native)

I’m having hassle mixing the “and” and “or” effectively… in get_posts.

As an illustration I can do one thing like:

$posts = get_posts(array( 'category__and' => array(1,10) )); // assuming 10=class Europe, 1 =class 2016,

So I simply do a loop like

Foreach $12 months in checklist of years:
  foreach $sort in checklist of varieties
     get_posts(array( 'category__and' => array($12 months,$sort) ));

Is there a extra environment friendly solution to mix my circumstances?

Thanks

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments