|

How to filter Query Parameters in Advanced Posts?

Advanced posts are loved by a lot of people due to its flexibility to modify query parameters. But, in some cases, developers need to modify the query parameters which are not specified in options. Let’s say you are displaying events using Advanced posts module and you want to disregard past events. Let’s assume that the event date is specified in meta with key `event_date`. Also we are checking with HTML id `events-list` before modifying the parameters so that this won’t be applied to all blog post modules on the site.

 /* Advanced Query Parameters filtering for UABB Posts module */ 
function your_prefix_uabb_blog_posts_query_args( $args, $settings ) {
// Give an HTML id and check it before modifying arguments so that it will not be applied to all blog post modules on the site.
if ( $settings->id == 'events-list' ) {
$args['orderby'] = '';
$args['meta_key'] = 'event_date';
$args['nopaging'] = true;
$args['posts_per_page'] = '2';
$args['meta_query'] =
array(
'key' => 'event_date',
'compare' => '<', 'value' => date( "Ymd" ),
'type' => 'DATE'
);
}
return $args;
}
add_filter( 'uabb_blog_posts_query_args', 'your_prefix_uabb_blog_posts_query_args', 20, 2 );

We are using `uabb_blog_posts_query_args` filter to accomplish this. You can take a look at all our filter reference.
You need to put the above code snippet in functions.php file of your theme/child theme.

This is just one example. You have lots of possibilities to filter posts with WP Query Parameters.

Was this doc helpful?
What went wrong?

We don't respond to the article feedback, we use it to improve our support content.

On this page

  ⏳  Hurry Up! It’s Your Golden Hour for Cyber Monday Savings!

00
Months
00
Days
00
Hours
00
Minutes
00
Seconds

WAIT!!

You’re Missing the Biggest Discount of the Year!

00
Months
00
Days
00
Hours
00
Minutes
00
Seconds

Grab this rare opportunity to save up to 50%

100% Risk-Free Money Back Guarantee!

Download is Just A Click Away!

Enter your email address and be the first to learn about updates and new features.

Download Free Ultimate Addon For Beaver Builder Plugin - Modal Popup Form

Free Download

Enter your name & email address to download this awesome freebie.

Free Download

Enter your name & email address to download this awesome freebie.

Free Download

Enter your name & email address to download this awesome freebie.

Free Download

Enter your name & email address to download this awesome freebie.

Free Download

Enter your name & email address to download this awesome freebie.

Free Download

Enter your name & email address to download this awesome freebie.

Free Download

Enter your name & email address to download this awesome freebie.

Free Download

Enter your name & email address to download this awesome freebie.

Free Download

Enter your name & email address to download this awesome freebie.

Free Download

Enter your name & email address to download this awesome freebie.

Free Download

Enter your name & email address to download this awesome freebie.

Free Download

Enter your name & email address to download this awesome freebie.

Scroll to Top