The ubermenu_dynamic_posts_args
filter allows you to filter the post query arguments array just before it is passed to get_posts
for Dynamic Posts.
Here’s an example of using the filter. We’ll target a Dynamic Post item with the ID 562. The demonstrates how you’d alter the query arguments, in this example changing the offset or the sorting.
function um_filter_dynamic_post_args( $post_args , $menu_item_id ){ //Target menu item 562 if( $menu_item_id == 562 ){ //Change offset to 5 $post_args['offset'] = 5; //Change orderby to random $post_args['orderby'] = 'rand'; } return $post_args; } add_filter( 'ubermenu_dynamic_posts_args' , 'um_filter_dynamic_post_args' , 10 , 2 );
ubermenu_dynamic_posts_args
Your registered callback will be called once for each dynamic post item. The array you return will be passed as query arguments to the get_posts() function. You have access to the query arguments (with parameters set in the menu item settings already present) and the ID of the Dynamic Posts item.